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