Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-14-2011, 08:35 PM   #1
LQ Newbie
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
Smile Scripting to copy FTP files between servers

I'd like to know if there is an example of writing a script to copy files from one server to another using FTP?
Old 09-15-2011, 01:59 AM   #2
Registered: Aug 2009
Location: Umzinto, South Africa
Distribution: Crunchbangified Debian 8 (Jessie)
Posts: 747
Blog Entries: 1

Rep: Reputation: 172Reputation: 172
Try using wget from the target server
Old 09-15-2011, 02:35 AM   #3
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Or use a here document:
ftp -ni ftp.address.or.ip << EOF 1> $HOME/ftp.log 2> $HOME/ftp.err
  user username password
  put file
Another tool that has much more flexibility than the standard ftp client is lftp. In this case you can use a subshell to generate the commands and pipe them to lftp:
  echo open ftp.address.or.ip
  echo user username password
  echo binary
  echo put file
  echo bye
) | lftp -f /dev/stdin
Old 09-15-2011, 02:37 AM   #4
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,589

Rep: Reputation: 145Reputation: 145
in Perl you can do as described here
Old 09-15-2011, 02:47 AM   #5
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202

Rep: Reputation: 36
If you want to use colucix's script and avoid using the user and the password in your script you can use ~/.netrc to store your ftp users and passwords, and protect just that file from curious eyes. Its format is:

machine login your_user password your_password

By the way, lftp allows you to put all the info as parameters and not having to pipe results to it. It would be something like

lftp [ftp|sftp|ftps]://your.ftp.machine -u your_user,your_pass 2>&1 > bla bla bla

Last edited by rodrifra; 09-15-2011 at 02:53 AM.
Old 09-15-2011, 11:55 AM   #6
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,267

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
is it possible to just use scp with keys or are you married to ftp ?


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automate FTP / Scripting FTP Transfers files from linux to windows m/c ashishshukla Programming 5 05-26-2016 10:10 AM
Script to copy some files with ftp after searching in the directory..... LQ zunkie Linux - General 7 04-26-2011 05:23 AM
how to use ftp in linux to copy files from remote system. helpdeskmtv General 2 10-29-2007 11:26 AM
Using scp to copy files between servers. muskiediver Linux - General 1 07-11-2006 04:52 PM
Software needed for pushing files to ftp servers. Napper Linux - Software 6 04-02-2005 03:20 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:35 PM.

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