LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-18-2003, 07:36 PM   #1
efishta
LQ Newbie
 
Registered: Jul 2003
Posts: 3

Rep: Reputation: 0
Can I make a Cron job to synch/transfer a file from a folder to another FTP?... read


I've got a file hosted in one of the folder of my website account running on Linux. What I'd like to see if its possible to create a Cron Job to synch that specific file to the another folder on another website (via FTP I would guess)

The reason for this is that it's a highly requested file that in turn is consuming a lot of bandwidth and is updated almost daily by another user of my site with FTP privileges. I've setup a redirect to the file on the other site, but I would like for the synching to happen automatically, instead of me by hand. Or is there another way to do this? Cron jobs is the only thing that came to mind but I don't know if it's designed for such use.
 
Old 07-18-2003, 10:04 PM   #2
slapNUT
Member
 
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144

Rep: Reputation: 15
Try this
 
Old 07-18-2003, 10:22 PM   #3
gabriele_101
Member
 
Registered: Oct 2001
Location: CAMBRIDGE, MA USA
Distribution: RH9 Kernel 2.4.20-18.9
Posts: 69

Rep: Reputation: 15
I'm not sure that I understand the problem. Do you want to syncronize one file (it changes on two or more machines and the changes need to be propagated to all machines) or is there one file that changes on one machine and you want to push/pull those changes to one or more other machines?

If yours is the latter case and this is a page that is "served" to the public, I would put a cron job on the receiving machinge using wget or GET since this way you do not need to store passwords in files on either machine. Both wget and GET can fetch files that are only newer than a certain date, so you'll have to write a tiny wrapper script for the cron job to get/store the file date of last downloaded file.

Come to think of it, if you have lwp-mirror installed, it will do it all for you w/o a wrapper. And rsync could do it too, but again, there are security issues.

-G
 
Old 07-18-2003, 11:14 PM   #4
efishta
LQ Newbie
 
Registered: Jul 2003
Posts: 3

Original Poster
Rep: Reputation: 0
the changes are on one machine and it needs to be synched to another machine... the problem here is that the machine where I do have access to cron jobs is the one where the file changes, and the machine where I want to transfer the files to I only have FTP access.

sooo, there are 2 solutions as far as I can see. One is to run a program in the background on my PC to periodically synch 2 FTP folder on 2 separate servers (via a utility of some kinds, i'm sure i've seen one or two before)

or the other is to run that command suggested in the first reply to my thread above, but as I understand it, that link above explains how to pull a file. I want to actually upload a file to the other machine. I'm assuming, since Linux has every command imaginable, it probably has an upload command as well.
 
Old 07-19-2003, 12:26 AM   #5
gabriele_101
Member
 
Registered: Oct 2001
Location: CAMBRIDGE, MA USA
Distribution: RH9 Kernel 2.4.20-18.9
Posts: 69

Rep: Reputation: 15
In that case you may want to look at ncftpput (part of the ncftp distro). Assuming that changing_file is the file that you want to upload a script like this should work in cron:

Code:
#!/bin/bash --norc
file=changing_file

if test ! -e $file.upload_time
  then
    touch $file.upload_time
fi

if test $file -nt $file.upload_time
  then
    if ncftp -u some_user -p some_password \
        some.host.org /home/me/upload_dir $file
      then
        date >> $file.upload_time
     else
        echo -n "ERROR: Did not upload file! "
        date >> $file.upload_time
     fi
fi
WARNING I have not tested this, just whipped this up in the "reply" box. Use at your own risk. But I think it will work

-G
 
Old 07-19-2003, 04:25 AM   #6
efishta
LQ Newbie
 
Registered: Jul 2003
Posts: 3

Original Poster
Rep: Reputation: 0
that package doesn't exist on my host's server. Thank you for taking the time to help me though.

However, I did quite a bit of research after I discovered rsync that is installed on my host's computer.

Does anyone have any experience with rsync? like I said above, I would need to sync a file from a local folder on the Linux server to another server via FTP.
 
Old 07-19-2003, 11:03 PM   #7
slapNUT
Member
 
Registered: Jun 2001
Location: Recycle Bin
Distribution: Linux & Everything else on VirtualBox
Posts: 144

Rep: Reputation: 15
Well using the link I provided above you could write a script that access the first server ftp and get the file, then quit that server and access ftp the second server and put the file.

IE create a text file named 'ftpscript1.txt' with:

user username password
cd subdirectory
prompt
get file
quit

and run 'ftp -n ftp.server1.com <ftpscript1.txt'

Then create a text file named 'ftpscript2.txt' with:

user username password
cd subdirectory
prompt
put file
quit

and run 'ftp -n ftp.server2.com <ftpscript2.txt'


You may need to put binary in the ftpscriptX.txt file.


NOTE: This is from the link above and I just modified it to your problem, and did not test it.

So you would have a script like this:

#!/bin/bash
ftp -n ftp.server1.com <ftpscript1.txt
ftp -n ftp.server2.com <ftpscript2.txt

Then you run crontab to add the file.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make a simple code for just restarting Apache via a Cron job hsa Programming 1 08-22-2005 05:15 AM
cron job to send file via ftp every 1 hour mcalizo Linux - Newbie 1 07-14-2004 04:50 AM
cron job that email a text file paynsr Linux - Newbie 1 03-29-2004 02:36 PM
need a perlscript to read from a text file and transfer files via ftp cccc Linux - Networking 2 02-21-2004 07:18 PM
howto delete files via ftp from cron job ? cccc Linux - Networking 2 01-31-2004 07:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration