How can I move a file to a webserver every 5 minutes?

I'm using Ubuntu and I have a text file I want to FTP to a web server every 5 minutes. I want to overwrite the existing file every time so I don't have tons of the same file.

For scheduling the file's transfer use cron manager, or whatever is available under Ubuntu. For the FTP transfer - what have you done so far ? Should this task be script, if yes, what language you have knowledge in ? Else, you can always look at the forum's base, there are many examples on how to automate file transfer via shell script for example.

Some ftp servers are set up not to allow this or put version numbers on files that already exist. Check with the admin of the ftp server.
Also, be nice and write your script to only transfer the file if it has changed. I have a client who thinks it's just peachy to ftp me 5,000 files several time every day, always the same files.

try putting this in cron to run every 5 mins.

this should work:

wget ftp://username:password@someserver/somefile -O /where/to/put/the/file/filemane.ext

If you don't want to mess with crontab, just write a shell script that does and infinite loop with sleep(5m) inside it followed by the wget/ftp command to put the file there.

  1. keep your script running continuously is not a good option. Let cron do that.
  2. but yes create a script which will take a backup of your existing file. then remove old one and copy new one.
  3. Also keep check in script if it has been copied properly on remote server. you can use md5sum to check that.
  • $nilesh

Why isn't it a good option?

If the computer is rebooted, it will need to be restarted.

If the script crashes your need to restart it.

If the script hangs you will have to restart it.

If its in cron it will automatically run when needed even if anyov the above happends.

Create a file ".netrc" in the home dir of the user who will be FTPing the files to the webserver. The contents of .netrc file would be the following line:

machine webserver_ip_address login username password userpassword

The perms set to .netrc will be 400.
Now create the script in that users' home dir as:

#!/bin/bash
FILENAME="filename.txt"
ftp -n <<FEOF
verbose
prompt
bin
put $FILENAME
FEOF

Put it inside cron.

Now well u can definately make it run every 5 mins without putting it in a cron if u make it run as a daemon and also make it available in startup/shutdown scripts. In Linux make the sym link of this script in /etc/rc.d/local dir. That should be all.

One correction here.
Replace ftp -n with ftp web_server_ipaddress

Wouldn't it be better to use RSYNC? It is more secure then ftp. Install it and read the man page to know if it is possible to do a resynchronising of your local directory with that of your server in question every 5 min. Else write a script.