Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cron jobs to upload a file via FTP

Is it possible to use CRON to upload a file via FTP? If yes how can I call FTP to run an upload?

like image 969
text Avatar asked Jun 26 '09 02:06

text


People also ask

How do I automatically upload files to an FTP server?

Setting up automatic FTP scheduling is as easy as right-clicking on the folder or directory you want to schedule, and clicking Schedule. In the Task Scheduler section you'll be able to name the task, and set a date and time for the transfer to occur.


4 Answers

Assuming a UNIX-like operating system you could setup a cron job that pointed to a shell script like the following:

#!/bin/sh
cd [source directory]
ftp -n [destination host]<<END
user [user] [password]
put [source file]
quit
END

Depending on your ftp client defaults and the source file type you may need to specify binary prior to the put.

like image 113
Jay Igor Avatar answered Sep 28 '22 07:09

Jay Igor


You may use ncftp -- they have an handy tools called "ncftpput"

It is easier then using expect -- it is just a single command with useful return code.

like image 30
J-16 SDiZ Avatar answered Sep 28 '22 08:09

J-16 SDiZ


You probably are looking for a program called "expect" which is designed for dealing with interactive processes.

http://expect.nist.gov/

If you have "cron", you likely already have "expect" as well, these days.

like image 37
smcameron Avatar answered Sep 28 '22 08:09

smcameron


Schedule a script call from cron.
In the script,

  • Use Public Key Authentication to open a Secure FTP communication with your server
  • Execute a batch file of PUTs to your server (there is a -b option in sftp)

For this,

  • you will need to setup the public key authentication between the server and your client,machine.
  • you will need a sftp client on the client machine (there are clients for all platforms -- PuTTY, Winscp.net, unix variants usually have this already installed).
  • finally, try the PUT manually with public key authentication and note down the commands -- you can write them down in to the batch file for automation

Some other notes.

  • expect is an overkill for this requirement.
  • More over, any scheme that requires the password to be scripted is bad
  • ncftp is good for an interactive session (not such automation)
  • I do not know if wput allows public key authentication (probably not), in which case its not good for such automation either
like image 35
nik Avatar answered Sep 28 '22 08:09

nik