How to use ftp in a shell script

If you want to send a file to FTP server for backup or for any other reason,
create new script file with your favorite editor
# vi /usr/bin/ftp_put.sh
and copy the next lines to it

#!/bin/sh
HOST='ftp server'
USER='user name'
PASSWD='password'
FILE='$1'

ftp -n $HOST
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

change the "ftp server", "user name" and "password" to your needs.
after saving the file, run the next command
# chmod +x /usr/bin/ftp_put.sh

That's it
run this command to send file to your ftp server
# ftp_put.sh /any/file/you/want


No comments:

Post a Comment