LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 04-10-2008, 02:52 AM   #1
chenboly
LQ Newbie
 
Registered: May 2007
Posts: 7

Rep: Reputation: 0
script for make schedule for automatically download file from ftp site


Dear All,
somebody have experience to make a script to run in schedule for automatically download file from FTP?

Best Regards;
Boly
 
Old 04-10-2008, 03:30 AM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
duplicate message

Last edited by Agrouf; 04-10-2008 at 03:39 AM.
 
Old 04-10-2008, 03:38 AM   #3
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
I have.
You need man, crontab and ftp, alternatively curl or wget.

echo "machine foobarhost login foo password bar" >>~/.netrc
cat >/usr/local/bin/dostuff <<EOF
echo "bin
get /there/foo.bar /here/foo.bar" | ftp foobarhost
EOF
EDITOR=vi crontab -e
00 00 * * * /usr/local/bin/dostuff
:wq
 
Old 04-10-2008, 04:12 AM   #4
chenboly
LQ Newbie
 
Registered: May 2007
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks Agrouf, but I don't understand can you make bit detail then this.

Best Regards;
Boly
 
Old 04-10-2008, 05:51 AM   #5
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
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

Regards,
Agrouf

Last edited by Agrouf; 04-10-2008 at 05:57 AM.
 
Old 04-10-2008, 06:24 AM   #6
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Rep: Reputation: 15
Good description man.
 
Old 10-05-2015, 04:41 AM   #7
mcchalk
LQ Newbie
 
Registered: Oct 2015
Posts: 1

Rep: Reputation: Disabled
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.
 
  


Reply



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
Fast Download Site for Linux, enables >4GB Download of single file TigerLinux Linux - Distributions 9 10-29-2005 12:45 PM
Download from ftp site freezes browser bongski55 Linux - General 2 09-17-2005 01:59 AM
How to write a shell script to download a file via FTP? guarriman Linux - General 4 12-21-2004 09:31 AM
how can i use a ftp program to download a site? Laptop2250 General 2 07-04-2004 05:30 PM
is there any linux command to download files from any ftp site remotely midnitc Linux - General 3 10-31-2003 08:05 AM

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

All times are GMT -5. The time now is 01:38 PM.

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