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

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

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

      Okay, so I was able to get it to actually upload a file...sort of. I made these changes:

      $sftp->setcwd("/root/svcftp/sftp") or die "=[\n" . $sftp->error; $sftp->put("/usr/local/nagios/Misc/sftptest", "/root/svcftp/sftp/sftpt +est") or die "Can't put\n" . $sftp->error;

      What I mean by "sort of" is that I see the file appear in the directory on my FTP server, but I still get an error on the put method. The error is :

      Couldn't setstat remote file: SSH_FILEXFER_ATTR_PERMISSIONS at line 33 +.

      I also wanted to include the latest debug from sftp in case that helps.

      #2237 1409090663.00000 new: This is Net::SFTP::Foreign 1.77 #2237 1409090663.00000 new: Loaded from /usr/local/lib/perl/5.14.2/Net +/SFTP/Foreign.pm #2237 1409090663.00000 new: Running on Perl v5.14.2 for linux #2237 1409090663.00000 new: debug set to -1 #2237 1409090663.00000 new: ~0 is 18446744073709551615 #2237 1409090663.00000 new: Using backend Net::SFTP::Foreign::Backend: +:Unix 1.76_03 #2237 1409090663.00000 _queue_msg: queueing msg len: 5, code:1, id:3 . +.. [1] 00 00 00 05 01 00 00 00 03 + | ......... #2237 1409090663.00000 _get_msg: waiting for message... [1] #2237 1409090663.00000 _do_io: _do_io connected: 1 #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io write queue: 9, syswrite: 9, max +: 65536, $!: 00 00 00 05 01 00 00 00 03 + | ......... #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io read sysread: 9, total read: 9, +$!: 00 00 00 05 02 00 00 00 03 + | ......... #2237 1409090663.00000 _get_msg: got it!, len:5, code:2, id:-, status: + - 02 00 00 00 03 + | ..... #2237 1409090663.00000 _rel2abs: '/root/svcftp/sftp' --> '/root/svcftp +/sftp' #2237 1409090663.00000 _queue_msg: queueing msg len: 26, code:16, id:0 + ... [1] 00 00 00 1a 10 00 00 00 00 00 00 00 11 2f 72 6f 6f 74 2f 73 76 63 66 7 +4 70 2f 73 66 74 70 | ............./root/svcftp/sftp #2237 1409090663.00000 _get_msg: waiting for message... [1] #2237 1409090663.00000 _do_io: _do_io connected: 1 #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io write queue: 30, syswrite: 30, m +ax: 65536, $!: 00 00 00 1a 10 00 00 00 00 00 00 00 11 2f 72 6f 6f 74 2f 73 76 63 66 7 +4 70 2f 73 66 74 70 | ............./root/svcftp/sftp #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io read sysread: 115, total read: 1 +15, $!: 00 00 00 6f 68 00 00 00 00 00 00 00 01 00 00 00 11 2f 72 6f 6f 74 2f 7 +3 76 63 66 74 70 2f 73 66 | ...oh............/root/svcftp/sf 74 70 00 00 00 45 64 72 77 78 72 2d 78 2d 2d 2d 20 32 20 66 74 70 61 6 +4 6d 69 6e 20 66 74 70 61 | tp...Edrwxr-x--- 2 ftpadmin ftpa 64 6d 69 6e 20 20 20 20 20 20 20 20 30 20 4a 61 6e 20 30 31 20 31 39 3 +7 30 20 2f 72 6f 6f 74 2f | dmin 0 Jan 01 1970 /root/ 73 76 63 66 74 70 2f 73 66 74 70 00 00 00 04 00 00 01 e8 + | svcftp/sftp........ #2237 1409090663.00000 _get_msg: got it!, len:111, code:104, id:0, sta +tus: - 68 00 00 00 00 00 00 00 01 00 00 00 11 2f 72 6f 6f 74 2f 73 76 63 66 7 +4 70 2f 73 66 74 70 00 00 | h............/root/svcftp/sftp.. 00 45 64 72 77 78 72 2d 78 2d 2d 2d 20 32 20 66 74 70 61 64 6d 69 6e 2 +0 66 74 70 61 64 6d 69 6e | .Edrwxr-x--- 2 ftpadmin ftpadmin 20 20 20 20 20 20 20 20 30 20 4a 61 6e 20 30 31 20 31 39 37 30 20 2f 7 +2 6f 6f 74 2f 73 76 63 66 | 0 Jan 01 1970 /root/svcf 74 70 2f 73 66 74 70 00 00 00 04 00 00 01 e8 + | tp/sftp........ #2237 1409090663.00000 _rel2abs: '/root/svcftp/sftp' --> '/root/svcftp +/sftp' #2237 1409090663.00000 _queue_msg: queueing msg len: 26, code:17, id:1 + ... [1] 00 00 00 1a 11 00 00 00 01 00 00 00 11 2f 72 6f 6f 74 2f 73 76 63 66 7 +4 70 2f 73 66 74 70 | ............./root/svcftp/sftp #2237 1409090663.00000 _get_msg: waiting for message... [1] #2237 1409090663.00000 _do_io: _do_io connected: 1 #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io write queue: 30, syswrite: 30, m +ax: 65536, $!: 00 00 00 1a 11 00 00 00 01 00 00 00 11 2f 72 6f 6f 74 2f 73 76 63 66 7 +4 70 2f 73 66 74 70 | ............./root/svcftp/sftp #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io read sysread: 25, total read: 25 +, $!: 00 00 00 15 69 00 00 00 01 00 00 00 3c 00 00 41 e8 53 fd 03 07 53 fd 0 +1 35 | ....i.......<..A.S...S..5 #2237 1409090663.00000 _get_msg: got it!, len:21, code:105, id:1, stat +us: - 69 00 00 00 01 00 00 00 3c 00 00 41 e8 53 fd 03 07 53 fd 01 35 + | i.......<..A.S...S..5 #2237 1409090663.00000 _rel2abs: '/root/svcftp/sftp/sftptest' --> '/ro +ot/svcftp/sftp/sftptest' #2237 1409090663.00000 put: local file size is 17 #2237 1409090663.00000 _rel2abs: '/root/svcftp/sftp/sftptest' --> '/ro +ot/svcftp/sftp/sftptest' #2237 1409090663.00000 _queue_msg: queueing msg len: 47, code:3, id:2 +... [1] 00 00 00 2f 03 00 00 00 02 00 00 00 1a 2f 72 6f 6f 74 2f 73 76 63 66 7 +4 70 2f 73 66 74 70 2f 73 | .../........./root/svcftp/sftp/s 66 74 70 74 65 73 74 00 00 00 1a 00 00 00 04 00 00 01 ed + | ftptest............ #2237 1409090663.00000 _get_msg: waiting for message... [1] #2237 1409090663.00000 _do_io: _do_io connected: 1 #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io write queue: 51, syswrite: 51, m +ax: 65536, $!: 00 00 00 2f 03 00 00 00 02 00 00 00 1a 2f 72 6f 6f 74 2f 73 76 63 66 7 +4 70 2f 73 66 74 70 2f 73 | .../........./root/svcftp/sftp/s 66 74 70 74 65 73 74 00 00 00 1a 00 00 00 04 00 00 01 ed + | ftptest............ #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io read sysread: 16, total read: 16 +, $!: 00 00 00 0c 66 00 00 00 02 00 00 00 03 31 33 34 + | ....f........134 #2237 1409090663.00000 _get_msg: got it!, len:12, code:102, id:2, stat +us: - 66 00 00 00 02 00 00 00 03 31 33 34 + | f........134 #2237 1409090663.00000 open: new remote file '/root/svcftp/sftp/sftpte +st' open, rid: 31 33 34 + | 134 #2237 1409090663.00000 _queue_msg: queueing msg len: 20, code:10, id:3 + ... [1] 00 00 00 14 0a 00 00 00 03 00 00 00 03 31 33 34 00 00 00 04 00 00 01 e +d | .............134........ #2237 1409090663.00000 _get_msg: waiting for message... [1] #2237 1409090663.00000 _do_io: _do_io connected: 1 #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io write queue: 24, syswrite: 24, m +ax: 65536, $!: 00 00 00 14 0a 00 00 00 03 00 00 00 03 31 33 34 00 00 00 04 00 00 01 e +d | .............134........ #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io read sysread: 50, total read: 50 +, $!: 00 00 00 2e 65 00 00 00 03 00 00 00 08 00 00 00 1d 53 53 48 5f 46 49 4 +c 45 58 46 45 52 5f 41 54 | ....e............SSH_FILEXFER_AT 54 52 5f 50 45 52 4d 49 53 53 49 4f 4e 53 00 00 00 00 + | TR_PERMISSIONS.... #2237 1409090663.00000 _get_msg: got it!, len:46, code:101, id:3, stat +us: 8 65 00 00 00 03 00 00 00 08 00 00 00 1d 53 53 48 5f 46 49 4c 45 58 46 4 +5 52 5f 41 54 54 52 5f 50 | e............SSH_FILEXFER_ATTR_P 45 52 4d 49 53 53 49 4f 4e 53 00 00 00 00 + | ERMISSIONS.... #2237 1409090663.00000 _set_status: _set_status code: 8, str: SSH_FILE +XFER_ATTR_PERMISSIONS #2237 1409090663.00000 _set_error: _set_err code: 24, str: Couldn't se +tstat remote file: SSH_FILEXFER_ATTR_PERMISSIONS #2237 1409090663.00000 DESTROY: Net::SFTP::Foreign::FileHandle=GLOB(0x +1660708)->DESTROY called (sftp: Net::SFTP::Foreign=HASH(0x167f098)) #2237 1409090663.00000 _queue_msg: queueing msg len: 12, code:4, id:4 +... [1] 00 00 00 0c 04 00 00 00 04 00 00 00 03 31 33 34 + | .............134 #2237 1409090663.00000 _get_msg: waiting for message... [1] #2237 1409090663.00000 _do_io: _do_io connected: 1 #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io write queue: 16, syswrite: 16, m +ax: 65536, $!: 00 00 00 0c 04 00 00 00 04 00 00 00 03 31 33 34 + | .............134 #2237 1409090663.00000 _do_io: _do_io select(-,-,-, undef) #2237 1409090663.00000 _do_io: _do_io read sysread: 21, total read: 21 +, $!: 00 00 00 11 65 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 + | ....e................ #2237 1409090663.00000 _get_msg: got it!, len:17, code:101, id:4, stat +us: 0 65 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 + | e................ #2237 1409090663.00000 _close: closing file handle, return: 1, rid: 31 33 34 + | 134 Can't put Couldn't setstat remote file: SSH_FILEXFER_ATTR_PERMISSIONS at /usr/lo +cal/nagios/Working/sftp_fresh.pl line 33. #2237 1409090663.00000 DESTROY: Net::SFTP::Foreign=HASH(0x167f098)->DE +STROY called (current pid: 2237, disconnect_by_pid: ) #2237 1409090663.00000 disconnect: Net::SFTP::Foreign=HASH(0x167f098)- +>disconnect called (ssh pid: 2241) #2237 1409090663.00000 _conn_lost: _conn_lost #2237 1409090663.00000 disconnect: process 2241 reaped