Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by amchidam (Initiate)
on Mar 17, 2016 at 18:13 UTC ( [id://1158137]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1158137]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found