Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to create a cron job that uploads files from a directory on my computer to my FTP server. I would like it to do it daily at midnight. I know pretty much nothing about cron, so I apologize if I sound stupid!

share|improve this question

migrated from stackoverflow.com May 22 '10 at 22:14

This question came from our site for professional and enthusiast programmers.

This should go on to superuser.com as this is not a programming related question. –  t0mm13b May 22 '10 at 15:38

3 Answers 3

This is an FTP sample script to transfer one file: (Note you can use an FQDN instead of IP)


# $1 is the file name for the you want to tranfer
# usage: this_script  <filename>
domain = sample.domain.ftp
password= password

ftp -n > ftp_$$.log <<EOF
 open $IP_address
 USER $username $password
 put $1

Add the > ftp_$$.log only if you need logging. Then you can use the

crontab -e

command to edit the cronjob table and add your script.

This is an Example:

If you liked to have a the script above, (assume you have it in home and its name is myscript.sh) /home/myscript.sh, run every day at 2am, you have to do:

# crontab -e

and then you have to add the following entry:

0 2 * * * /home/myscript.sh

As a reference, here you have a crontab entry parameters meaning:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

This tutorial could also help you.

share|improve this answer

man crontab will show you what you need. You'll want something like:

0 0 * * *  yourScript.sh

in your crontab file. Note that scripts under cron run with a cut-down environment, so you'll have to specify your env settings that the script requires in that script.

share|improve this answer

man 1 ftp says that -u URL file [...]:

Upload files on the command line to URL where URL is one of the ftp URL types as supported by auto-fetch (with an optional target filename for single file uploads), and file is one or more local files to be uploaded.

Thus something like

0 0 * * * /usr/bin/ftp -u "ftp://example.com/dir" file1 file2

would upload files file1 and file2 to directory dir at example.com

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.