in reply to Couldn't get handle : Failure at line 11,sftp a file in perl

Are you sure that the connection to $ip worked? How can you tell? (You don't have any code in this snippet that shows you are checking.)

BTW, you probably want to use Net::SFTP::Foreign or Net::SSH2 instead. See Net::SFTP::Foreign Vs. Net::SFTP Vs. Net::SSH2::SFTP.

  • Comment on Re: Couldn't get handle : Failure at line 11,sftp a file in perl

Replies are listed 'Best First'.
Re^2: Couldn't get handle : Failure at line 11,sftp a file in perl
by amchidam (Initiate) on Mar 18, 2016 at 06:35 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