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

Hi all, i was trying to sftp my file from server to server using perl script

my $sftp = Net::SFTP->new($ip,%args); $sftp->put($localfile,$remortdir); ->this was line no 11

I got some error in 11th line like "Couldn't get handle : Failure at line 11"

could any one give a fine solution for this

Replies are listed 'Best First'.
Re: Couldn't get handle : Failure at line 11,sftp a file in perl
by Mr. Muskrat (Canon) on Mar 17, 2016 at 19:58 UTC

      Here is the code

      #!/usr/bin/perl use Net::SFTP; print "Connecting...\n"; my $sftp = Net::SFTP->new('www.asd....', user=>'usead..', password=>'pass..') or die "could no +t open connection\n"; $sftp->ls("." , sub { print $_[0]->{longname}, "\n" }); my($stdout)=$sftp->status; print $stdout."\n"; print "Connected!\n"; $sftp->put("/var/tmp/prac/hi.txt",'/var') or die "...problem !..."; print "\nFinished\n";

      output:

      Connecting...

      drwxr-xr-x 4 root root 512 Mar 25 01:33 ..

      -rw-r--r-- 1 axadmin gadmin 66 Oct 26 2004 .profile

      -rw-r--r-- 1 axadmin gadmin 283 Apr 26 2004 .tcshrc

      -rwx------ 1 axadmin gadmin 265 Jan 28 04:48 .bash_profile

      drwxr-xr-x 3 axadmin gadmin 512 Jan 28 23:55 asusmconf

      0

      Connected!

      Couldn't get handle: Failure at sft.pl line 14

      ...problem !... at sft.pl line 14.

      I can't able to use Net::SFTP::Foreign, as Foreign module is not available.

        Assuming you have write permisions for /var try adding filename

        $sftp->put("/var/tmp/prac/hi.txt",'/var/hi.txt') or die "...problem !...";
        poj