Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the simplest way to have a cronjob of ftp a file?

Status
Not open for further replies.

761210

IS-IT--Management
Jun 25, 2003
13
0
0
US
Hi guys,

wht would be the simplest way to ftp a file to another server with a cronjob?

 
Hi,

1) create .netrc file in you home directory. Permission 600. Content of .netrc file:

machine ftp_server_ip login login_name password your_pass

2) create a script to ftp the file automatically. Eg.

ftp -i<<EOF
open ftp_server_ip
ascii
cd /remote/ftp/location
lcd /local/ftp/location
put filename
get file
bye
EOF

Hope this help you.

feroz
 
Or for an option without the .netrc

<START SCRIPT>
#!/bin/sh
# ----------------------------------------
# FTP script
#
# This is where you specify the settings for the ftp
# Changes will be: host,user & password
# ----------------------------------------
host=nnn.nnn.nnn.nnn
user=USER
password=PASSWORD
destination=/path/to/somewhere
errorlog=/path/to/ftperror.txt
#------------------------------------
echo &quot;-----------------------------&quot; >> $errorlog
echo `date` >> $errorlog
echo &quot;-----------------------------&quot; >> $errorlog
ftp -v -n $host << EOF >> $errorlog
user $user $password
prompt
ascii
cd $destination
lcd /path/to/local/directory
mput *
quit
EOF
print &quot;Proces complete&quot;

<END SCRIPT>
If you want a more secure method use scp (secure copy) with public/private keys this way you encrypt your data while it is transferred.

As for the cron to run a script, cron is usually to run a process/script at a given time/date for nTimes, now you may need to produce a more detailed script if the cron is to run on a regular basis and not overwrite files on the reciveing end server.

You could also take a look at wget (as this has options that check if local file is newer than remote) that way you save bandwidth and prevent overwrites.

Good Luck
Laurie.
 
Feroz....is correct...I would also add that you might want to transfer your files in binary. Instead of ascii to do this simply put &quot;bi&quot; where ascii is in his outline.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top