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

Hi,


I need to move a file from server 2 to server 3, but both FTP and SSH should get initiated from server 1.

i.e
S1 (SSH)-> S2 (FTP)-> S3
file needs to be moved from S2 to S3. but the script running in S1. manually I am able to do it but through perl Net:FTP it is establishing session from server 1 instead of server 2
my code:
#!/usr/bin/perl -w use Net::FTP; use Net::SSH::Perl; my($host,$user,$pass) = ("Server2","user_name","password"); my $cmd = "whoami"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd($cmd); my $ftp = $ssh->cmd(Net::FTP->new("Server3", Debug => 0) or die "Canno +t connect to Server3 $@"); $ssh->cmd($ftp->login("user_name",'password') or die "Cannot login ", +$ftp->message); $ssh->cmd($ftp->cwd("/home/tmp") or die "Cannot change working directo +ry ", $ftp->message); $ssh->cmd($ftp->put("file_in_server2") or die "get failed ", $ftp->mes +sage); $ssh->cmd($ftp->quit);

Replies are listed 'Best First'.
Re: how to ftp files from a remote server 1 to server 2?
by vinoth.ree (Monsignor) on Jun 26, 2015 at 17:53 UTC
    Hi kpofcochin

    You need to have that ftp perl script in server2 an execute the ftp script from server1 by using Net::SSH::Perl


    All is well. I learn by answering your questions...
Re: how to ftp files from a remote server 1 to server 2?
by salva (Canon) on Jun 26, 2015 at 22:00 UTC
    Recent versions of OpenSSH support working as a SOCKS proxy (look for the -D option in ssh(1)). Then you will need also an FTP client supporting the SOCKS proxy protocol (for instance, firefox).

    There are also a couple of libraries that once preloaded enable transparently support for the SOCKS protocol in any application.

      thank you. i will try this
Re: how to ftp files from a remote server 1 to server 2?
by soonix (Chancellor) on Jun 28, 2015 at 16:22 UTC

    This sounds like you'd be interested in a special FTP usage called FXP.

    However, since this is prone to vulnerabilities, it is highly probable that the admins of server2 and server3 disabled it (or, depending on server system, didn't explicitly enable it).
    If they are fine with it (e.g. because it's an internal network), it should be possible to do it with $ftp->pasv and $ftp->port commands.

      thank you. let me try these