Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^5: sftp->do_write howto?

by insaniac (Friar)
on Sep 23, 2005 at 08:28 UTC ( [id://494432]=note: print w/replies, xml ) Need Help??


in reply to Re^4: sftp->do_write howto?
in thread sftp->do_write howto?

Very strange... maybe something's wrong with the module? Look, this is the code I used. I've tried connecting with an ssh key (so without username and pass), it works; I've also tried with a username and pass, it also works.
use Net::SFTP; use Net::SFTP::Constants qw/:flags/; use strict; use warnings; my $filename = "testfile.dat"; my $payload = "qwertyuiop"; my %args; $args{user} = "insaniac"; $args{password} = "xxxx"; #my $host = "moretrix.com"; my $host = "bear"; my $path = $filename; print "file $path\n"; print "connecting\n"; my $sftp = Net::SFTP->new($host,%args) ; print "open\n"; my $handle = $sftp->do_open($path, SSH2_FXF_WRITE | SSH2_FXF_CREAT); print "write\n"; $sftp->do_write($handle, 0, $payload); print "close\n"; $sftp->do_close($handle);
I don't think anything's wrong with your code, what version are you using? Is the pathname on the remotehost correct and do you have permission to write in that directory (very important!!! the first time I thought your $path variable was a local path!) This is the output I always get:
connecting open write close
Maybe try marto 's code above with your login credentials and try uploading a file (to the same $path), see if that works. Otherwise... I have no more ideas :-/

Update: Code is updated to use idsfa's suggestion

to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-23 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found