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

I am trying to use Net::SCP on the linux to copy files from a linux machine to a Windows machine. I can do so using command line as:
scp local_file user@windows_host:/dir
with password prompt. However the following perl script net_scp.pl doesn't work.
use strict; use warnings; use Net::SCP; my $file = 'xyz.txt'; my $destdir = '/dir'; my $host = 'xxx.xxx.xxx.xx'; my $user = 'user'; my $pass = 'pass'; my $scpe = Net::SCP::Expect->new(host => $host, user => $user, password => $pass) || die "Can not make connection to: $host\n"; $scpe->scp($file,$destdir) || die "can't scp: $!\n";
The error msg is: Problem performing scp: lost connection at ./net_scp.pl line 28. The line 28 is the last line above. But the same username and password worked fine on the command line. Any help will be greatly appreciated. Thanks much.

-----Inline Attachment Follows----- ------------------------------------------------------------------------------ RSA® Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1 -----Inline Attachment Follows----- _______________________________________________ Ssh-sftp-perl-users mailing list Ssh-sftp-perl-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users Go to Previous message | Go to Next message | Back to Messages | Full Headers Reply Reply All Forward Forward Mail Search WelcomeInboxNewFoldersMail Options

Replies are listed 'Best First'.
Re: Net::SCP can't connect to Windows server
by Khen1950fx (Canon) on Nov 01, 2011 at 03:43 UTC
    You forgot to load Net::SCP::Expect.
    #!/usr/bin/perl use strict; use warnings; use Net::SCP::Expect; my $file = '/path/to/xyz.txt'; my $destdir = '/tmp'; my $host = '127.0.0.1'; my $user = 'user'; my $scpe = Net::SCP::Expect->new( host => $host, user => $user, password => 'password', auto_yes => 1, verbose => 1, debug => 1, timeout_auto => 2, ); die "can't scp: $!\n" unless $scpe->scp($file, $destdir);
      No, forgetting to load Net::SCP::Expect would result is a very different error. Of course, that means the OP didn't post the code he actually ran, which is greatly going to limit the help we can give and the effort we will give.
        Thank you all for your responses. The problem has been solved. I have to specify the directory on the windows side as:
        my $destdir = '/C/Data/';
        instead of
        my $destdir = "C:\\Data\\";
        Thank you very much for your reply. My actual command line is:
        scp /tmp/data.txt user@123.456.789.24:"C:\\Data\\"
        after password prompt, it worked fine. My first question is: how do I specify windows destination directory? I used:
        my $destdir = '"C:\\Data\\"';
        I got the error: scp timed out while trying to connect to "C at ./net_scp.pl line 33 What is the correct directory specification on the windows side? Thanks much.
Re: Net::SCP can't connect to Windows server
by Anonymous Monk on Nov 01, 2011 at 02:55 UTC
    Turn on debugging/logging feature