Can I make a Cron job to synch/transfer a file from a folder to another FTP?... read
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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
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.
Distribution: Linux & Everything else on VirtualBox
Posts: 144
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.