Below shell script demonstrate the usage of FTP operation from within the bash script, feel free to copy and use this script:
Source: cat autoftp.sh
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Please provide the file path for ftp operation."
exit
fi
USERNAME=linuxpoison
PASSWORD=password
FILENAME="$1"
FTP_SERVER=ftp.foo.com
echo "Starting the ftp operation ...."
ftp -n $FTP_SERVER <<Done-ftp
user $USERNAME $PASSWORD
binary
put "$FILENAME"
bye
Done-ftp
echo "Done with the transfer of file: $FILENAME"
exit
Output: ./autoftp.sh log.tar.gz
Starting the ftp operation ....
Done with the transfer of file: log.tar.gz
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Please provide the file path for ftp operation."
exit
fi
USERNAME=linuxpoison
PASSWORD=password
FILENAME="$1"
FTP_SERVER=ftp.foo.com
echo "Starting the ftp operation ...."
ftp -n $FTP_SERVER <<Done-ftp
user $USERNAME $PASSWORD
binary
put "$FILENAME"
bye
Done-ftp
echo "Done with the transfer of file: $FILENAME"
exit
Output: ./autoftp.sh log.tar.gz
Starting the ftp operation ....
Done with the transfer of file: log.tar.gz
2 comments:
Thank you. Is there any way to "hide" my password within the script so it is not visible?
no, best way to read the password from DB or from some other secured file.
Post a Comment