Automating FTP I: UNIX and Linux

Having gotten tired of repeated typing in everything at the prompt of an interactive command line FTP session and doing similar things via GUI route, I started to wonder if there was a scripting alternative and, lo and behold, I found it after a spot of googling. There are various opportunities for its extension such as prompting for user name and password instead of the risky approach of including them in a script or cycling through a directory structure but here’s the foundation stone for such tinkering anyway:

HOSTNAME=’ftp.server.host’
USER=’user’
PSSWD=’password’
REP_SRC=’source_directory’
REP__DEST=’destination_directory’
FILENAME=’*’

rm -rf log_file.tmp

cd "${REP_DEST}"

ftp -i -n -v <<EndFTP >>log_file.tmp 2>>log_file.tmp
open ${HOSTNAME}
user ${USER} ${PSSWD}
prompt
cd "${REP_SRC}"
mget "${FILENAME}"
EndFTP

cd ~

2 comments

Supposing that there is an FTP server running on the UNIX side, all that’s needed is to use ftp commands or something like FileZilla if you prefer a GUI.

Leave a Reply