LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 09-14-2011, 07:35 PM   #1
jfrancis
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, 12:59 AM   #2
qlue
Member
 
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
http://www.editcorp.com/Personal/Lar...v1/wget_7.html
 
Old 09-15-2011, 01:35 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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
 
Old 09-15-2011, 01:37 AM   #4
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
in Perl you can do as described here

http://search.cpan.org/~gbarr/libnet-1.22/Net/FTP.pm
 
Old 09-15-2011, 01:47 AM   #5
rodrifra
Member
 
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 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

Last edited by rodrifra; 09-15-2011 at 01:53 AM.
 
Old 09-15-2011, 10:55 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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


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 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 09:10 AM
Script to copy some files with ftp after searching in the directory..... LQ zunkie Linux - General 7 04-26-2011 04:23 AM
how to use ftp in linux to copy files from remote system. helpdeskmtv General 2 10-29-2007 10:26 AM
Using scp to copy files between servers. muskiediver Linux - General 1 07-11-2006 03:52 PM
Software needed for pushing files to ftp servers. Napper Linux - Software 6 04-02-2005 02:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:21 AM.

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