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

After connecting to server1 using Net::OpenSSH you can just use Expect to launch scp there against server2 and handle the password authentication.

You can see in Net::OpenSSH documentation how to combine it with Expect.

Another alternative is to configure public key authentication from your machine to both server1 and server2 and then use the authentication agent forwarding feature of SSH to enable ssh'ing from server1 to server2 without storing any keys in server1 (it is usually a bad idea to enable password-less authentication between servers as that can be easily exploitable by any attacker to move freely between servers).

Replies are listed 'Best First'.
Re^2: Copy file from one sereve to another server directly.
by dilip.patel (Initiate) on Nov 13, 2014 at 14:06 UTC
    Hi, Salva

    For tempporary, I had implemented it by using Net::SFTP::Foreign. I had created 2 separate object of Net::SFTP::Foreign, one for reading from server1 and another for writing on server2. But its taking too much time(For 50mb file it is taking ~30min). Since data from server1 is coming to local machine and then it going to server2.

    I had read how to combine Net::OpenSSH with Expect but I am not getting how to use it for scp. Please give me an example of how to use Expect for scp. If you dont mind.

      Update: ignore me. tobyink already said the same thing.

      Assuming that keys are set up properly for passwordless ssh/scp access like so:

      local ---SSH--> server1 ---SCP--> server2

      If I were to do this from the command line, I would do something along the lines of:

      local$ ssh server1 'scp $file server2:$remote_file'

      Implementing this in perl is left as an exercise for the reader :-)

      --MidLifeXis