Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix FTP script

Status
Not open for further replies.
Jun 16, 2003
8
US
Hi,

I need to connect to a remote system and download files from a certain directory. I already have a script that does just that, however, for each file I download, I have to move it to an ARCHIVE directory on the remote system. Can anyone help in giving me tips on doing this? Can this be done within one FTP connection or will I need to get a list of files and then connect again to download the files from the list that was created?

Any help would be greatly appreciated.

Here is the script I already have:

#!/bin/sh

clear

# changing working directory

cd /COMM

# Setting variables
WNAME=ftp.abccompany.com
FTPU=User
FTPP=Password

# starting ftp process

echo "CONNECTING... "
ftp -n -v $WNAME <<EOF
user $FTPU $FTPP
cd /OUT
bin
prompt off
umask 0
mget file*.*
mv file*.* ARCHIVE
bye
EOF

Thank you,
analyst1411
 
You could use ksh co-processes to do this with one FTP connection. Here's a starting point with no error-checking, etc:

Code:
ftp -inv ftp.abccompany.com 1> ftp.out 2>&1 |&

print -p "user User Password"
print -p "cd /OUT"
print -p "bin"
print -p "prompt off"
print -p "umask 0"
print -p "mget file*.*"
print -p "dir file*.* filelist"
while read line
do
        filename=`echo $line | awk '{print $NF}'`
        print -p "ren $filename ARCHIVE/$filename"
done < filelist

print -p "bye"

There is no mv command in FTP, you have to use ren to "rename" each individual file to its new location.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top