Saturday 13 December 2014

FTP download file using Bash script

Recently, I need to download a file daily from external FTP site, process the downloaded file locally and store the result into database. Below is the part of bash script to download a file. Just run the Bash file with Cron, job well done.




cd $DIR_TO_STORE_FILE_DOWNLOADED

# Call 1. Uses the ftp command with the -inv switches.  -i turns off interactive prompting. -n Restrains FTP from attempting the auto-login feature. -v enables verbose and progress.

ftp -inv $HOST << EOF

# Call 2. Here the login credentials are supplied by calling the variables.
user $USER $PASS
get $FILE_NAME_TO_DOWNLOAD
bye
EOF