Last month I had to find a way to automate the transfer of files from a UNIX database server to a Windows fileshare via the pre-existing FTP method. This was previously executed manually. The trouble I ran into was passing the FTP commands from a UNIX shell script to the Windows FTP server (specifically, user credentials) correctly. Second, I also wanted to automate the process of archiving these files to a new directory after transfer. Here’s what I came up with, variables requiring your modification in bold:
################################################################################ #************************* Script Title ****************************** # # Script Name: FTP PUT TO WINDOWS FTP SERVER # Script Filename: FTP_PUT_TO_WINFTPSERVER.sh # # #********************* Script Description ************************************ # # This shell script will look for files matching 'FTP_*.dat' and FTP any # found to a Windows FTP server, then archive them in a folder named # the current date. # #************************* Modification Log ******************************* # # Date Name Description #_____________________________________________________________________________ # # 10/19/2011 Bryce Baker Original script # #******************************************************************************* ################################################################################ #!bin/sh #***** Set local working directory ***** cd /path/to/script/and/files #***** Set ftp server, credentials, and file(s) to search for ***** HOST='SERVERADDRESS' USER='FTPUSERNAME' PASSWD='FTPPASSWORD' FILE='FTP_*.dat' #***** Send files to FTP server ***** ftp -vn $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD prompt n mput $FILE quit END_SCRIPT #***** Archive files ***** #***** Set DATE variable to current date ***** DATE='20'`date '+%y%m%d'` mkdir $DATE mv $FILE /path/to/archive/folder/$DATE/ exit 0