ftp: get list of file to get. Retrieve and move them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ftp: get list of file to get. Retrieve and move them
# 1  
Old 12-15-2007
Question ftp: get list of file to get. Retrieve and move them

Hi,

I need to get multiple files from an ftp server. Once the files have been downloaded, I need to move them to a different directory on the ftp server. I don't know of a command that would enable me to get a file and then move it (assuming I don't know the exact file name) within ftp. I think the best way would be to connect to the FTP server and write the list of files waiting to be downloaded to a text file, then connect again and download one file at a time, but I don't know how to do it.

If anyone has some suggestions to get me started it would be grately appreciated.

Thanks.
# 2  
Old 12-15-2007
Quote:
Originally Posted by bbabr
I need to move them to a different directory on the ftp server. I don't know of a command that would enable me to get a file and then move it (assuming I don't know the exact file name) within ftp.
try "rename"
# 3  
Old 12-15-2007
Can't do that. I can either move to a differnt directory or delete. My problem is getting the list of files and then reading from the list to issue the GET and RENAME for each file.

Thanks for the quick reply.
# 4  
Old 12-15-2007
Quote:
Originally Posted by bbabr
Can't do that. I can either move to a differnt directory or delete. My problem is getting the list of files and then reading from the list to issue the GET and RENAME for each file.

Thanks for the quick reply.
pseudo-code....

Code:
ftp host >list.txt <<EOF
ls
quit
EOF
while read N
do
      echo >>todo.lst get $N
      echo >>todo.lst rename $N got/$N
done
echo >>todo.lst quit
ftp host <todo.lst

# 5  
Old 12-16-2007
porter,

Thanks for the quick reply. I was able to write the list of files to list.txt but I'm having problems reading the list and putting it in todo.lst. Am I missing something in between? How do I specify to the system to read N from list.txt?

Thanks again.
# 6  
Old 12-16-2007
Quote:
Originally Posted by bbabr
How do I specify to the system to read N from list.txt?
Yup I missed that bit...

Code:
while read N
do
        ....
done <list.txt

# 7  
Old 12-16-2007
That did the job!

I managed to get the file list, create the todo.lst and run it. One thing I found, though, is that you have to delete the todo.lst after running the script. If not, the next time you run it, it will append to the file.

Below is the script I have. Any comments and suggestions on making it better would be greatly appreciated.

Code:
#!/bin/sh
clear
# change local directory
cd [local-directory]

#collect file names
ftp -ni ftp.abccompany.com <<EOF
user [user] [password]
cd /OUT
mls W945*.* list.txt 
quit
EOF

# create ftp action list
echo >>todo.lst user [user] [password]
while read N
do
    echo >>todo.lst cd /OUT
    echo >>todo.lst get $N
    echo >>todo.lst rename $N ARCHIVE/$N
done <list.txt

echo >>todo.lst quit

# ftp transfer process
ftp -nv ftp.abccompany.com <todo.lst

# cleanup
rm todo.lst

Thanks again!
This User Gave Thanks to bbabr For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move file from one directory and update the list file once moved.

Dears, I have a listfile contains list of files path. i need to read the line of the listfile mv the file to other directory and update the listfile by deleting the lines of the listfile. #!/bin/bash target=/fstest/INVESTIG/Sadiq/TEST_ARCH while read -r line || ]; do mv $line... (19 Replies)
Discussion started by: sadique.manzar
19 Replies

2. Shell Programming and Scripting

List the file names available on FTP server before selecting the required file

Below is my script code.which shows the environment name and then fetch the file from the ftp server but I am facing one issue.The script should be run in both way.We can pass the arguments with script and select the environment name then file name.Here the issue is I am not able to list the files... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

3. UNIX for Dummies Questions & Answers

Move file using a file list

Hello, I have a text file name "filelist" which stores the file names of the files I want to move (the file names does not include the directory). Each of the name is in 1 line, and all the file are in directory: /cluster/home/input (along with other unrelated files). I want to move all the... (7 Replies)
Discussion started by: warmboy610
7 Replies

4. Shell Programming and Scripting

How to move a file in ftp command to other location?

hi, when i do ftp from unix to laptop which is running a windows os, it lands in a root folder. can i move a file from this root ftp folder to any other location in my laptop say , c:\files\ folder? i used rename command inside ftp , but it says incorrect parameter. (5 Replies)
Discussion started by: Little
5 Replies

5. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

6. Shell Programming and Scripting

Retrieve lines that match any occurence in a list of patterns

I have two files. The first containing a header and six columns of data. Example file 1: Number SNP ID dbSNP RS ID Chromosome Result_Call Physical Position 787066 SNP_A-8575395 RS6650104 1 NOCALL 564477 786872 SNP_A-8575125 RS10458597 1 AA ... (13 Replies)
Discussion started by: Selftaught
13 Replies

7. Shell Programming and Scripting

How to move the older than 30 file to another ftp server

Hi All I need to move the older than 30 days file to another ftp server. I have source structure like this Files folder Folder1 Folder2 Folder3 I need to create same Target structure and I need to move the older than 30 day file to another ftp server, can you please suggest me how I develop... (1 Reply)
Discussion started by: murari83.ds
1 Replies

8. Shell Programming and Scripting

awk to retrieve the particular value from a same list of xml tags

Hi All, I have the following code in one of my xml file: <com:parameter> <com:name>secretKey</com:name> <com:value>31XA874821172E89B00B1C</com:value> </com:parameter> <com:parameter> <com:name>tryDisinfect</com:name> <com:value>false</com:value> </com:parameter> <com:parameter>... (4 Replies)
Discussion started by: mjavalkar
4 Replies

9. Shell Programming and Scripting

After FTP unable to move file to other location

Hi Experts, I am using below script and facing some problems.. cd /home/user/test rm ftp://ftp.log Example: A_Bachfile_09292011.txt A=`ls -1 "A*.txt"` compress $A C=`ls -1 "A*` hostname="test.gmail.com" user="raju" Password="******" ftp -n $hostname <<EOF >>ftp.lpg... (4 Replies)
Discussion started by: rajubollas
4 Replies

10. Shell Programming and Scripting

how to move a file from one server to another server using FTP in shell script?

I have a file --> file1.txt i need to copy this file to another server using FTP....the 2 servers are server1 and server2..may i know how to write a script that can do this? thanks in advance! Im a newbie to this... (4 Replies)
Discussion started by: forevercalz
4 Replies
Login or Register to Ask a Question