in reply to Re: How to connect to SFTP via OpenSSH
in thread How to connect to SFTP via OpenSSH

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.

Replies are listed 'Best First'.
Re^3: How to connect to SFTP via OpenSSH
by tangent (Parson) on Aug 26, 2014 at 01:24 UTC
    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...?

        Folder not found: sftptest
        This is the error returned by the remote server. Looks like some Windows server, I would not expect too much from it.

        Enable debugging of Net::SFTP::Foreign at the beginning of your script to see what is actually happening under the hood:

        $Net::SFTP::Foreign::debug = -1;
        ...and post here the output.
        Try:
        $sftp->put($putFile,'/path/to/remote/file');