in reply to How to connect to SFTP via OpenSSH

I tried your script and it worked fine for me, i.e. it created the sftp object and I was able to retrieve a file. Try adding:
my $sftp = $ssh->sftp() or die "Can't create sftp: " . $ssh->error;

Replies are listed 'Best First'.
Re^2: How to connect to SFTP via OpenSSH
by Logic_Bomb421 (Novice) on Aug 26, 2014 at 00:25 UTC

    ALright, so when I add the error string to the end of my sftp() method, it returns:

    Permission denied (publickey, password). unable to establish master SSH connection: bad password or master proc +ess exited unexpectedly at line 23

    I've tested the password in one of my SFTP clients just to be sure everything was right and it worked fine.

      Your problem is that you are not making the SSH connection in the first place. Where you have:
      $ssh = Net::OpenSSH->new(host=>$host, user=>$user, password=>$pw) or d +ie "can't :(\n" . $ssh->error;
      that is not actually testing for failure as new() always succeeds - from the Net::OpenSSH docs:
      This method always succeeds in returning a new object. Error checking +has to be performed explicitly afterwards: my $ssh = Net::OpenSSH->new($host, %opts); $ssh->error and die "Can't ssh to $host: " . $ssh->error;
      I suspect one of your parameters is incorrect. When I log in via SSH I use: ssh username@username.example.com. That translates to:
      my $host = "username.example.com"; my $user = "username"; my $pw = "password";
      Also, if you use public key authentication (which you really should) then you need to provide the path to your key.

        You were right about incorrect credentials. I was able to resolve that issue. Now for some reason it fails when trying to put a file on my SFTP server. I get the message:

        Can't put. Couldn't open remote file 'sftptest': Folder not found: sftptest at line 25.

        So why is it looking for a folder called sftptest when putting? I've clearly defined that as a file? Also, what does it mean "can't open remote file"? This isn't a remote file yet...?