Is it possible to use CRON to upload a file via FTP? If yes how can I call FTP to run an upload?
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.
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
.
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.
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.
Schedule a script call from cron
.
In the script,
PUT
s to your server (there is a -b
option in sftp
)For this,
sftp
client on the client machine (there are clients for all platforms -- PuTTY, Winscp.net, unix variants usually have this already installed).Some other notes.
expect
is an overkill for this requirement. ncftp
is good for an interactive session (not such automation)wput
allows public key authentication (probably not), in which case its not good for such automation eitherIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With