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

  1. atul tandon says:

    how to I ftp from unix to linux.

  2. John says:

    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.

  • As is commonly the case with places like these, all the views that you find expressed on here in postings and articles are mine alone and not those of any organisation with which I have any association, through work or otherwise. With regards to any comments left on the site, I reserve the right to reject any that are inappropriate. Otherwise, whatever is said is the sole responsibility of whoever is leaving the comment.

Private