views:

853

answers:

5

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

A: 

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.

smcameron
A: 

Just create your CRON jobs to call WGET to upload or download your file via FTP!

backslash17
Actually, you'd rather want to use wput(http://wput.sourceforge.net/) to put stuff on the remote server.
tomzx
A: 

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.

J-16 SDiZ
+1  A: 

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.

Jay Igor
A: 

Schedule a script call from cron.
In the script,

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
nik