Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to send records from one ftp server folder to another ftp server folder? If so, is there any example code in Perl Monks? I have the Logins and passwords for both servers. Thanks a million

2005-10-10 Retitled by planetscape, as per Monastery guidelines
Original title: 'ftp'

  • Comment on How to share records between ftp servers?

Replies are listed 'Best First'.
Re: How to share records between ftp servers?
by marto (Cardinal) on Oct 10, 2005 at 13:19 UTC
      Thanks, this was very helpful.
Re: How to share records between ftp servers?
by samizdat (Vicar) on Oct 10, 2005 at 13:56 UTC
    A bit of caution from personal experience:

    Net::FTP does work, but it's a bit limited. Net::FTP::Recursive solves a few of the problems, but not all. I just had a case where I was fetching 16000+ small (8-15Kbytes) files from a WinNT server on a network with varying loads to a FreeBSD server on which the script resides. It took several hours with Net::FTP and failed to fetch a number of files. It was trying to create a new connection for each file transfer, and timing out with 'Unable to close connection' as its warning on STDERR.

    When I manually FTP'd the files, the mget operation took less than 15 minutes, and all the files came across. Seeing this, I dug into man ftp. In there, I discovered (actually, rediscovered: I had done this before on an embedded system) that you can have ftp read its login and command sequence from a file.

    From Perl:
    use strict; use warnings; # ... chdir('/path/to/put/files/in'); system('ftp', '-N', 'mystartfile', 'ftp.server.com') && die "FTP FAI +LURE: $!\n"; chdir('/where/I/was/before'); # ...
    the file mystartfile:
    machine ftp.server.com login me password somesillypw binary cd /path/to/fetch/from mget * bye
    This code has your Perl program waiting for completion of the FTP transfer. If this is not necessary, write the system command like so:
    system('ftp -N mystartfile ftp.server.com &') && die "Couldn't start f +tp transfer: $!\n";
      Questions: My cgi program is on one ftp server and I want to copy a file to a ftp remote server programmatically. I have the IP address of the remote server, will I need the path to the folder I want to copy the file to?
        Yes, you will want to change the cd line in mystartfile and change the machine line to reflect your IP address. You will also want to change the mget line to put myfile. If you want more flexibility than this, please read man ftp.
Re: How to share records between ftp servers?
by Grygonos (Chaplain) on Oct 10, 2005 at 13:20 UTC
Re: How to share records between ftp servers?
by Zaxo (Archbishop) on Oct 10, 2005 at 18:47 UTC

    The scp utility can copy files from one remote to another, without moving through the local machine. Net::SCP provides a Perl interface.

    That's very handy if you're working through a slow connection.

    After Compline,
    Zaxo

Re: How to share records between ftp servers?
by murugu (Curate) on Oct 10, 2005 at 13:35 UTC

    Try Net::FTP.

    Regards,
    Murugesan Kandasamy.

Re: How to share records between ftp servers?
by ides (Deacon) on Oct 10, 2005 at 18:39 UTC
    Just an FYI, but if you're moving files from one server to another server, you'll need to download them first to wherever your script that uses Net::FTP resides before sending them on to the recipient server.

    Frank Wiles <frank@wiles.org>
    http://www.wiles.org

      That's not strictly always true. If the remote source server supports it, ftp permits a remote to remote transfer to be initiated by a third party client. See pasv() and pasv_xfer() calls in NET::ftp.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
        WOW! Learn something new everyday. I've been using or running FTP servers for gosh about 13 years now and never knew this feature existed. Thanks!

        Frank Wiles <frank@wiles.org>
        http://www.wiles.org