in reply to Copy file from one sereve to another server directly.

Take a look at the Net::SCP module. This should give you the tools you need. To quote the example from the module documentation:

use Net::SCP; $scp = Net::SCP->new( { "host"=>$hostname, "user"=>$username } ); $scp->scp($source, $destination);

Still, it assumes that you can login to the host without prompting for password (you have exchanged the SSH keys). If you want to automate the password prompt, there is a another module: Net::SCP::Expect. This should work as a starting point.

#!/usr/bin/perl use strict; use v5.14; use Net::SCP::Expect; my $user = 'u'; my $pass = 'p'; my $host = '127.0.0.1'; my $src_path = "/tmp/test/"; my $dst_path = "/tmp/"; my $s = Net::SCP::Expect->new; $s->login($user, $pass); $s->scp($src_path,"$host:$dst_path");

Pick one to your liking, and good luck with the task ahead of you.

UPDATE: added Net::SCP::Expect example.

- Luke

Replies are listed 'Best First'.
Re^2: Copy file from one sereve to another server directly.
by tobyink (Canon) on Nov 10, 2014 at 14:39 UTC

    I'm pretty sure that in this case the data will still go via your machine.

    Direct server-to-server copying will probably be much faster. If the servers are within the same data centre, you might achieve speeds of up to several hundred MB per second. Even if they're not, most servers have pretty meaty connections, so you might achieve 50 to 200 MB per second.

    The basic trick is to set up passwordless authentication from server 1 to server 2, and passwordless authentication from your client machine to server 1. Then it's just a matter of:

    ssh 'user1@server1' 'scp' '/path/to/source' 'user@server2:/path/to/des +t'

    Note that the above should still work with password authentication, but you'll be prompted to enter server1's password, then server 2's password.

      I'm pretty sure that in this case the data will still go via your machine.

      I was assuming that OP wants to run the SCP script on one of the servers, and wrote my examples based on this assumption. Thank you for your reply, and making the critical advice about setting up the passwordless authentication - this should always be step 1.

      Still, you are making another assumption - it's possible that the task OP is trying to solve is caused by the fact that both servers don't have network access to each other. A good example (of a very bad practice) would be copying production data to a test environment, when the security rules prohibit direct network access between production and development. In such cases, traffic usually goes through the workstation of some unfortunate sysadmin. Not that I've ever seen it happen. It's so good that security policies are never violated in IT. ;)

      - Luke

Re^2: Copy file from one sereve to another server directly.
by dilip.patel (Initiate) on Nov 10, 2014 at 17:01 UTC

    Thanks, but Net::SCP::Expect is working only for remote to local and local to remote.

    I want something which should work for remote to remote also.

      tobyink has already guessed your intentions correctly, and I can only point you towards his good advice.

      - Luke