FTP uploading in BASH script

Solution 1:

Found this bash script online that has quality documentation:

#!/bin/bash

HOST=ftp.server.com  #This is the FTP servers host or IP address.
USER=ftpuser             #This is the FTP user that has access to the server.
PASS=password          #This is the password for the FTP user.

# 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

# Call 3. Here you will change to the directory where you want to put or get
cd /path/to/file

# Call4.  Here you will tell FTP to put or get the file.
put test.txt

# End FTP Connection
bye

EOF

After configuring and saving the .sh script, make it executable:

chmod +x ftpscript.sh

Lastly, configure your cronjob

Solution 2:

command in one line:

ftp -in -u ftp://username:password@servername/path/to/ localfile

Solution 3:

curl is capable of uploading file(s) to FTP servers.

curl -T "$FILE(s)" -u $USERNAME:$PASSWORD $SERVER/$DIR/

You can also use a glob pattern for $FILE.

Solution 4:

if you have 'curl', which is fairly standard, it can do unattended FTP uploads (see man page for the -T option)