1

I Need to create a Cronb that will run daily on my server and will ftp into a remote server with a username and password. It will copy a directory on that server and copy it onto a directory on my server. I then want the files to be deleted on the remote server.

Can someone help me with doing this?

1
  • Let me add this all needs to be done via terminal – Juan Ducos May 12 '16 at 17:32
1

Use following command to edit your cron job:

crontab -e

Then add following to the end of that:

0 0 * * * lftp -u username,password -e "your command;quit" ftp.site.com

Obviously you must install lftp package beforehand.

1
  • is lftp my only option? – Juan Ducos May 12 '16 at 17:39
1

Use crontab -e to open your crontab file. Then add:

0 3 * * * rsync -raz --remove-source-files 'user:password@remotehost:/directory/to/copy' '/local/destination/directory/'

This tells cron to run this command every day at 3 AM. Adjust the first 5 parameters (0 3 * * *) as necessary to adjust the time when this runs and how often it runs

The rsync command does the following:

  1. -r: recursively, i.e. get everything in the source directory and in directories under it
  2. -a: archive, i.e. keep as much as the source information about the file as possible
  3. -z: compress the data on the source before sending it
  4. --remove-source-files: Remove the files on the source system (the remote system in this case) once complete
10
  • "--remove-soruce-files" is this where i want the files copied – Juan Ducos May 12 '16 at 17:42
  • No, that's /local/destination/directory at the end – Mitch May 12 '16 at 17:43
  • its giving me Bash: !@(IP): event not found – Juan Ducos May 12 '16 at 17:50
  • All source args must come from the same machine. rsync error: syntax or usage error (code 1) – Juan Ducos May 12 '16 at 17:57
  • 1
    root@reports:~# rsync -raz --remove-source-files apple:test123@173.203.**.***:/apple/file /mnt/file ssh: Could not resolve hostname apple: Name or service not known rsync: connection unexpectedly closed (0 bytes received so far) [Receiver] rsync error: unexplained error (code 255) at io.c(605) [Receiver=3.0.9] – Juan Ducos May 12 '16 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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