script for make schedule for automatically download file from ftp site
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.
Let say you want to automatically download the file named "foo.bar" which is located on a ftp server named "foobarhost.net", under the "/there" directory. You want to schedule it every night at midnight and you want the file to be downloaded on your local machine to directory "/here".
The administrator of fooberhost.net is paranoid, so he uses accounts with password to let you connect with ftp. He gives you the account foo, whose password is bar.
So, the first step is to make so that your machine is able to automatically connect to foobarhost.net without you manually typing the password.
the ftp command uses a file named ".netrc" for that, which is located in your home directory.
You can edit it to add the password for the user foo for the machine foobarhost.net :
echo "machine foobarhost.net login foo password bar" >>~/.netrc
This will add the required line in the specified file. You can also use gedit or kwrite or vi to do that is you like.
Note this file must not be read by anybody, for obvious security reasons.
Let's change the read access so you are the only one who can access it:
chmod 600 ~/.netrc
Now we need a command that does the download so we can launch it automatically at midnight.
Let's call that command dostuff. Inside, we put the command to download foo.bar from /there at foobarhost.net:
echo "bin
get /there/foo.bar /here/foo.bar" | ftp foobarhost.net
This tells ftp to download foo.bar in binary mode from foobar.net/there to /here
We save the command file to dostuff under /usr/local/bin with gedit/vi/whatever
And last step is to schedule this command every day at midnight.
Use the crontab -e command for that.
add the line
00 00 * * * /usr/local/bin/dostuff
and save the file.
This tells cron to launch /usr/local/bin/dostuff every day of month (*) of every month(*) every day of the week (*) at 00:00
Great, now let's wait for midnight to see if it worked.
In the mean time, we can learn more about the different commands we used from the manual pages:
man ftp
man crontab
first of all sorry i know this is a really old post but a quick google of what i need and this came up top
Agrouf seems like the man that could help me with this. I need to schedule a download of a file from an ftp. i want to give it a schedule start and stop time if possible or a way to manually start and stop it would work. but most importantly i need it to repeat the task every minute and to check the file size and resume the download if it bigger than what is already downloaded.
Long shot i know!
I have a program called flashFXP for windows which does this in windows but it requires setting a windows scheduled task so when i try in Linux i doesnt work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.