Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to upload the entire content of a directory /home/test to my ftp server, in a specific folder. I will then schedule the script hourly via cron. Any examples?

NB. consider that I'm on a Netgear ReadyNAS Duo (a debian box) and I can't install lftp or similars, only standard commands :)

share|improve this question
What do you mean "standard commands"? Bash has no "standard command" for ftp. – DerfK Jun 10 '11 at 14:38
Is the Netgear ReadyNAS Duo the machine you want to copy from or to? You are unable to install any sort of software or run scripts on it? Is there a possibility of initiating the connection on the FTP server and pulling down the files? – Clinton Blackmore Jun 10 '11 at 15:25
up vote 11 down vote accepted

Found this bash script online that has quality documentation:

#!/bin/bash  #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


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

chmod +x

Lastly, configure your cronjob

share|improve this answer
this is the correct answer. thanks. – Fabio B. Jun 13 '11 at 9:26
this stores the password in plain text in your script. a better solution would be: user $USER ftp will then prompt for a password. – expz Dec 10 '14 at 16:13
@expz I'm not sure how having the terminal prompt for a password is compatible with scheduling it to run hourly in a cron job... – Michael Shaw Jun 22 '15 at 14:12
I didn't notice. In that case, chmod a-rw+x would be a tiny bit of security. A more involved solution would use the default SSH key for security: $PASS=<decrypt a host.conn file using SSH key>; echo user = $USER:$PASS | curl --disable-epsv --ftp-skip-pasv-ip --digest --anyauth --ftp-ssl -K - -T /path/to/file /path/to/remote/dir – expz Jul 29 '15 at 16:58

command in one line:

ftp -in -u ftp://username:password@servername/path/to/ localfile
share|improve this answer
Is there a similar comment to list or download files – SeanClt Mar 24 at 15:08

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


You can also use a glob pattern for $FILE.

share|improve this answer

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

share|improve this answer

If ssh is installed and configured to allow file transfers you could use scp.

If not netcat or rsync may be an option.

share|improve this answer
no way. I have to make it work with ftp. – Fabio B. Jun 10 '11 at 15:16

If you are able to install or build programs, a utility called ftpsync may be just what you are looking for. [I've never tried it, and there seem to be several utilities either called that or something very similar.]

share|improve this answer

In a bash script you should be able to do something like:

    echo "
    USER ftpuser ftppasswd
    put /path/to/stuff.tar.gz
    " > ftp -n > ftp_$$.log

Tarring your directory first would be a good idea and make it much simpler. Also, depending on the size of your directory and the speed of your network, you may want to consider doing differential tars.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.