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

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...?

Replies are listed 'Best First'.
Re^5: How to connect to SFTP via OpenSSH
by salva (Canon) on Aug 26, 2014 at 18:10 UTC
    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.

      Alright this is what I get from the Net::SFTP::Foreign debug:

      #38418 1409077155.00000 new: This is Net::SFTP::Foreign 1.77 #38418 1409077155.00000 new: Loaded from /usr/local/lib/perl/5.14.2/Ne +t/SFTP/Foreign.pm #38418 1409077155.00000 new: Running on Perl v5.14.2 for linux #38418 1409077155.00000 new: debug set to -1 #38418 1409077155.00000 new: ~0 is 18446744073709551615 #38418 1409077155.00000 new: Using backend Net::SFTP::Foreign::Backend +::Unix 1.76_03 #38418 1409077155.00000 _queue_msg: queueing msg len: 5, code:1, id:3 +... [1] 00 00 00 05 01 00 00 00 03 + | ......... #38418 1409077155.00000 _get_msg: waiting for message... [1] #38418 1409077155.00000 _do_io: _do_io connected: 1 #38418 1409077155.00000 _do_io: _do_io select(-,-,-, undef) #38418 1409077155.00000 _do_io: _do_io write queue: 9, syswrite: 9, ma +x: 65536, $!: 00 00 00 05 01 00 00 00 03 + | ......... #38418 1409077155.00000 _do_io: _do_io select(-,-,-, undef) #38418 1409077155.00000 _do_io: _do_io read sysread: 9, total read: 9, + $!: 00 00 00 05 02 00 00 00 03 + | ......... #38418 1409077155.00000 _get_msg: got it!, len:5, code:2, id:-, status +: - 02 00 00 00 03 + | ..... #38418 1409077155.00000 _rel2abs: 'sftptest' --> 'sftptest' #38418 1409077155.00000 put: local file size is 17 #38418 1409077155.00000 _rel2abs: 'sftptest' --> 'sftptest' #38418 1409077155.00000 _queue_msg: queueing msg len: 29, code:3, id:0 + ... [1] 00 00 00 1d 03 00 00 00 00 00 00 00 08 73 66 74 70 74 65 73 74 00 00 0 +0 1a 00 00 00 04 00 00 01 | .............sftptest........... ed + | . #38418 1409077155.00000 _get_msg: waiting for message... [1] #38418 1409077155.00000 _do_io: _do_io connected: 1 #38418 1409077155.00000 _do_io: _do_io select(-,-,-, undef) #38418 1409077155.00000 _do_io: _do_io write queue: 33, syswrite: 33, +max: 65536, $!: 00 00 00 1d 03 00 00 00 00 00 00 00 08 73 66 74 70 74 65 73 74 00 00 0 +0 1a 00 00 00 04 00 00 01 | .............sftptest........... ed + | . #38418 1409077155.00000 _do_io: _do_io select(-,-,-, undef) #38418 1409077155.00000 _do_io: _do_io read sysread: 47, total read: 4 +7, $!: 00 00 00 2b 65 00 00 00 00 00 00 00 04 00 00 00 1a 46 6f 6c 64 65 72 2 +0 6e 6f 74 20 66 6f 75 6e | ...+e............Folder not foun 64 3a 20 73 66 74 70 74 65 73 74 00 00 00 00 + | d: sftptest.... #38418 1409077155.00000 _get_msg: got it!, len:43, code:101, id:0, sta +tus: 4 65 00 00 00 00 00 00 00 04 00 00 00 1a 46 6f 6c 64 65 72 20 6e 6f 74 2 +0 66 6f 75 6e 64 3a 20 73 | e............Folder not found: s 66 74 70 74 65 73 74 00 00 00 00 + | ftptest.... #38418 1409077155.00000 _set_status: _set_status code: 4, str: Folder +not found: sftptest #38418 1409077155.00000 _set_error: _set_err code: 2, str: Couldn't op +en remote file 'sftptest': Folder not found: sftptest #38418 1409077155.00000 open: open failed: Folder not found: sftptest Can't put Couldn't open remote file 'sftptest': Folder not found: sftptest at /u +sr/local/nagios/Working/sftp_fresh.pl line 27. #38418 1409077155.00000 DESTROY: Net::SFTP::Foreign=HASH(0x208fe38)->D +ESTROY called (current pid: 38418, disconnect_by_pid: ) #38418 1409077155.00000 disconnect: Net::SFTP::Foreign=HASH(0x208fe38) +->disconnect called (ssh pid: 38422) #38418 1409077155.00000 _conn_lost: _conn_lost #38418 1409077155.00000 disconnect: process 38422 reaped
        The client ask for opening a file for writting (2, SSH2_FXP_OPEN) and the server replies with a general failure code (4, SSH2_FX_FAILURE).

        I blame the server. For a work-around try using an absolute path or calling set_cwd first.

        Do you know which software is running on the server? if you connect to the ssh port using netcat or some similar tool it would tell the vendor and version of the SSH server.

Re^5: How to connect to SFTP via OpenSSH
by tangent (Parson) on Aug 26, 2014 at 19:55 UTC
    Try:
    $sftp->put($putFile,'/path/to/remote/file');