
September 29th, 2004, 01:19 PM
|
|
Contributing User
|
|
Join Date: Sep 2004
Posts: 60
Time spent in forums: 19 m 14 sec
Reputation Power: 4
|
|
Hi Shal,
Let me know how you get on with this.
Check out post "ftp in ksh program" by viswapsp below too...
Andy
You can amend in time to accept the remote node, the destdir, and maybe the username and password.
I think you'll always going to get a zero exit code from the ftp even if the file doesn't get transferred so don't rely on the exit code to determine if it's worked.
Code:
#!/usr/bin/ksh
#-- Set variables
FILE=$1 # the first parameter on the command line
CURRDATE=`date +%Y%m%d`
REMOTENODE=node_to_ftp_file_to
USERNAME=unix_account_on_remote_node
PASSWORD=password_of_unix_account
DESTDIR=destination_directory_for_file
#-- Check a file has been passed as a parameter to this script
if [[ -z "${FILE}" ]]; then
echo ERROR: file to process not passed
exit 10
fi
#-- Check the file exists
if [[ ! -f ${FILE} ]]; then
echo ERROR: ${FILE} does not exist or is not a regular file
exit 20
fi
#-- Rename file
mv ${FILE} ${FILE}.${CURRDATE}
#-- Get the filename of the FILE
FILENAME=`basename ${FILE}`
#-- Ftp the file
ftp <<END_OF_FTP
open ${REMOTENODE}
quote user ${USERNAME}
quote pass ${PASSWORD}
hash
put ${FILE} ${DESTDIR}/${FILENAME}
dir ${DESTDIR}/${FILENAME}
bye
END_OF_FTP
exit
|