LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Scripting to copy FTP files between servers (https://www.linuxquestions.org/questions/linux-newbie-8/scripting-to-copy-ftp-files-between-servers-903078/)

jfrancis 09-14-2011 07:35 PM

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?

qlue 09-15-2011 12:59 AM

Try using wget from the target server
http://www.editcorp.com/Personal/Lar...v1/wget_7.html

colucix 09-15-2011 01:35 AM

Or use a here document:
Code:

ftp -ni ftp.address.or.ip << EOF 1> $HOME/ftp.log 2> $HOME/ftp.err
  user username password
  binary
  put file
  bye
EOF

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:
Code:

(
  echo open ftp.address.or.ip
  echo user username password
  echo binary
  echo put file
  echo bye
) | lftp -f /dev/stdin


j-ray 09-15-2011 01:37 AM

in Perl you can do as described here

http://search.cpan.org/~gbarr/libnet-1.22/Net/FTP.pm

rodrifra 09-15-2011 01:47 AM

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 your.ftp.to.store 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

schneidz 09-15-2011 10:55 AM

is it possible to just use scp with keys or are you married to ftp ?


All times are GMT -5. The time now is 03:39 AM.