1753837 Members
9222 Online
108806 Solutions
New Discussion юеВ

FTP scripting

 
Grant Wenstrand
Occasional Advisor

FTP scripting

One of the responses to "Transfer files between two systems" referenced ftp scripting. I didn't think it could be done. Can someone please direct me to some good references as to how to do this?

Thanks,

Grant
2 REPLIES 2
Bill Hassell
Honored Contributor

Re: FTP scripting

Use a shell 'here' document (check a KSH or POSIX shell script manual for more details) and the non-interactive flag (-n) for ftp:

ftp -n << EOF
open some_host
lcd /tmp
cd /etc
ascii
get fstab
close
EOF

With here documents, env variables are expanded before being sent to ftp, making a general batch ftp possible as in:

MYHOST=cpu.mydomain.com
LOCALDIR=/tmp
REMOTEDIR=/etc
MYFILE=fstab

ftp -n << EOF
open $MYHOST
lcd $LOCALDIR
cd $REMOTEDIR
ascii
get $MYFILE
close
EOF


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: FTP scripting

Grant:

A recent thread touched on this. See "Automation of FTP Processes".

...JRF...