csftpteam has asked for the wisdom of the Perl Monks concerning the following question:

I am using the Net::SFTP::Foreign module to put and get files from a remote SFTP server. The put works fine but when I try to do a get and then delete the file, it throws these errors:

Couldn't open remote file 'test.txt': No such file.

Couldn't delete remote file: No such file. - test.txt

I am trying to get all files (*) and there is one file on the remote server named test.txt. Here is my code:
if (lc($transfertype) eq "get"){ $sftp_connection->setcwd($remote_dir); foreach my $file (@file_globs){ my @files = $sftp_connection->glob($file); foreach my $element (@files){ #if the remote file is a directory, we want to skip it. if (${$element}{longname} =~ /^d.*$/){ next; } else { $sftp_connection->get(${$element}{filename}, $local_di +r.${$element}{filename}); if ($sftp_connection->error == 0){ &logEntry($args{'logfile'}, "$jobname--Getting rem +ote file: \/".$remote_dir.${$element}{filename}); } elsif ($sftp_connection->error != 0){ &logEntry($args{'logfile'}, "$jobname-ERROR: ".$sf +tp_connection->error); } if ($delete_remote_files == 1){ $sftp_connection->remove(${$element}{filename}); if ($sftp_connection->error == 0){ &logEntry($args{'logfile'}, "$jobname--Deletin +g remote file:\/".$remote_dir."\/".${$element}{filename}); } elsif ($sftp_connection->error != 0){ &logEntry($args{'logfile'}, "$jobname-ERROR: " +.$sftp_connection->error." - ${$element}{filename}"); } } } } } }
We are using Net::SFTP::Foreign, v1.65, Solaris 10, and OpenSSH_5.8p2. When I manually connect to the SFTP site with the server's built-in SFTP client, I can get the file without any error messages. Any help with these errors would be great appreciated. Thanks!

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign stat Error
by salva (Canon) on Oct 26, 2011 at 16:35 UTC
    I am unable to reproduce the problem with the code you have posted.

    Try using a newer version of the module or even the current development version 1.68_08.

    Activate the module debugging:

    $Net::SFTP::Foreign::debug = -1;

    and post here the output or send it to me by email (BTW, I am the module author) as it may contain sensible data.

    In any case, glob does not set the longname slot on the returned hashes.

      Here is the debug output:

      #8888 1319651553.00000 _init_transport: ssh cmd: ssh -p 22 -o NumberOfPasswordPrompts=1 -o PreferredAuthentications=keyboard-interactive,password -l country sftp.jackmorton.com -s sftp #8888 1319651554.00000 _queue_msg: queueing msg len: 5, code:1, id:3 ... 1 00 00 00 05 01 00 00 00 03 | ......... #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 9, syswrite: 9, max: 65536, $!: 00 00 00 05 01 00 00 00 03 | ......... #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 9, total read: 9, $!: 00 00 00 05 02 00 00 00 03 | ......... #8888 1319651554.00000 _get_msg: got it!, len:5, code:2, id:-, status: - 02 00 00 00 03 | ..... #8888 1319651554.00000 _rel2abs: 'to_country' --> 'to_country' #8888 1319651554.00000 _queue_msg: queueing msg len: 19, code:16, id:0 ... 1 00 00 00 13 10 00 00 00 00 00 00 00 0a 74 6f 5f 63 6f 75 6e 74 72 79 | .............to_country #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 23, syswrite: 23, max: 65536, $!: 00 00 00 13 10 00 00 00 00 00 00 00 0a 74 6f 5f 63 6f 75 6e 74 72 79 | .............to_country #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 36, total read: 36, $!: 00 00 00 20 65 00 00 00 00 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 | ... e............No such file... 00 02 65 6e | ..en #8888 1319651554.00000 _get_msg: got it!, len:32, code:101, id:0, status: 2 65 00 00 00 00 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 00 02 65 6e | e............No such file.....en #8888 1319651554.00000 _set_status: _set_status code: 2, str: No such file. #8888 1319651554.00000 _set_error: _set_err code: 14, str: Couldn't get realpath for remote 'to_country': No such file. #8888 1319651554.00000 _rel2abs: '.' --> '.' #8888 1319651554.00000 _rel2abs: '.' --> '.' #8888 1319651554.00000 _queue_msg: queueing msg len: 10, code:11, id:1 ... 1 00 00 00 0a 0b 00 00 00 01 00 00 00 01 2e | .............. #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 14, syswrite: 14, max: 65536, $!: 00 00 00 0a 0b 00 00 00 01 00 00 00 01 2e | .............. #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 17, total read: 17, $!: 00 00 00 0d 66 00 00 00 01 00 00 00 04 00 00 00 00 | ....f............ #8888 1319651554.00000 _get_msg: got it!, len:13, code:102, id:1, status: - 66 00 00 00 01 00 00 00 04 00 00 00 00 | f............ #8888 1319651554.00000 opendir: new remote dir '.' open, rid: 00 00 00 00 | .... #8888 1319651554.00000 _queue_msg: queueing msg len: 13, code:12, id:2 ... 1 00 00 00 0d 0c 00 00 00 02 00 00 00 04 00 00 00 00 | ................. #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 17, syswrite: 17, max: 65536, $!: 00 00 00 0d 0c 00 00 00 02 00 00 00 04 00 00 00 00 | ................. #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 124, total read: 124, $!: 00 00 00 78 68 00 00 00 02 00 00 00 01 00 00 00 08 74 65 73 74 2e 74 78 74 00 00 00 3f 2d 72 77 | ...xh............test.txt...?-rw 2d 72 77 2d 72 77 2d 20 20 20 31 20 75 73 65 72 20 20 20 20 20 67 72 6f 75 70 20 20 20 20 20 20 | -rw-rw- 1 user group 20 20 20 31 31 32 20 4f 63 74 20 32 35 20 32 30 3a 31 37 20 74 65 73 74 2e 74 78 74 00 00 00 0f | 112 Oct 25 20:17 test.txt.... 00 00 00 00 00 00 00 70 00 00 00 00 00 00 00 00 00 00 81 b6 4e a7 19 3f 4e a7 19 3f | .......p............N..?N..? #8888 1319651554.00000 _get_msg: got it!, len:120, code:104, id:2, status: - 68 00 00 00 02 00 00 00 01 00 00 00 08 74 65 73 74 2e 74 78 74 00 00 00 3f 2d 72 77 2d 72 77 2d | h............test.txt...?-rw-rw- 72 77 2d 20 20 20 31 20 75 73 65 72 20 20 20 20 20 67 72 6f 75 70 20 20 20 20 20 20 20 20 20 31 | rw- 1 user group 1 31 32 20 4f 63 74 20 32 35 20 32 30 3a 31 37 20 74 65 73 74 2e 74 78 74 00 00 00 0f 00 00 00 00 | 12 Oct 25 20:17 test.txt........ 00 00 00 70 00 00 00 00 00 00 00 00 00 00 81 b6 4e a7 19 3f 4e a7 19 3f | ...p............N..?N..? #8888 1319651554.00000 _queue_msg: queueing msg len: 13, code:12, id:3 ... 1 00 00 00 0d 0c 00 00 00 03 00 00 00 04 00 00 00 00 | ................. #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 17, syswrite: 17, max: 65536, $!: 00 00 00 0d 0c 00 00 00 03 00 00 00 04 00 00 00 00 | ................. #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 35, total read: 35, $!: 00 00 00 1f 65 00 00 00 03 00 00 00 01 00 00 00 0c 45 6e 64 20 6f 66 20 66 69 6c 65 2e 00 00 00 | ....e............End of file.... 02 65 6e | .en #8888 1319651554.00000 _get_msg: got it!, len:31, code:101, id:3, status: 1 65 00 00 00 03 00 00 00 01 00 00 00 0c 45 6e 64 20 6f 66 20 66 69 6c 65 2e 00 00 00 02 65 6e | e............End of file.....en #8888 1319651554.00000 _set_status: _set_status code: 1, str: End of file. #8888 1319651554.00000 _set_error: _set_err code: 29, str: Couldn't read directory '.': End of file. #8888 1319651554.00000 _queue_msg: queueing msg len: 13, code:4, id:4 ... 1 00 00 00 0d 04 00 00 00 04 00 00 00 04 00 00 00 00 | ................. #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 17, syswrite: 17, max: 65536, $!: 00 00 00 0d 04 00 00 00 04 00 00 00 04 00 00 00 00 | ................. #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 31, total read: 31, $!: 00 00 00 1b 65 00 00 00 04 00 00 00 00 00 00 00 08 53 75 63 63 65 73 73 2e 00 00 00 02 65 6e | ....e............Success.....en #8888 1319651554.00000 _get_msg: got it!, len:27, code:101, id:4, status: 0 65 00 00 00 04 00 00 00 00 00 00 00 08 53 75 63 63 65 73 73 2e 00 00 00 02 65 6e | e............Success.....en #8888 1319651554.00000 _close: closing file handle, return: 1, rid: 00 00 00 00 | .... #8888 1319651554.00000 DESTROY: Net::SFTP::Foreign::DirHandle=GLOB(0xa76d08)->DESTROY called (sftp: ) #8888 1319651554.00000 _rel2abs: 'test.txt' --> 'test.txt' #8888 1319651554.00000 _rel2abs: 'test.txt' --> 'test.txt' #8888 1319651554.00000 _queue_msg: queueing msg len: 17, code:17, id:5 ... 1 00 00 00 11 11 00 00 00 05 00 00 00 08 74 65 73 74 2e 74 78 74 | .............test.txt #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 21, syswrite: 21, max: 65536, $!: 00 00 00 11 11 00 00 00 05 00 00 00 08 74 65 73 74 2e 74 78 74 | .............test.txt #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 36, total read: 36, $!: 00 00 00 20 65 00 00 00 05 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 | ... e............No such file... 00 02 65 6e | ..en #8888 1319651554.00000 _get_msg: got it!, len:32, code:101, id:5, status: 2 65 00 00 00 05 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 00 02 65 6e | e............No such file.....en #8888 1319651554.00000 _set_status: _set_status code: 2, str: No such file. #8888 1319651554.00000 _set_error: _set_err code: 19, str: Couldn't stat remote file (stat): No such file. #8888 1319651554.00000 _rel2abs: 'test.txt' --> 'test.txt' #8888 1319651554.00000 _queue_msg: queueing msg len: 25, code:3, id:6 ... 1 00 00 00 19 03 00 00 00 06 00 00 00 08 74 65 73 74 2e 74 78 74 00 00 00 01 00 00 00 00 | .............test.txt........ #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 29, syswrite: 29, max: 65536, $!: 00 00 00 19 03 00 00 00 06 00 00 00 08 74 65 73 74 2e 74 78 74 00 00 00 01 00 00 00 00 | .............test.txt........ #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 36, total read: 36, $!: 00 00 00 20 65 00 00 00 06 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 | ... e............No such file... 00 02 65 6e | ..en #8888 1319651554.00000 _get_msg: got it!, len:32, code:101, id:6, status: 2 65 00 00 00 06 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 00 02 65 6e | e............No such file.....en #8888 1319651554.00000 _set_status: _set_status code: 2, str: No such file. #8888 1319651554.00000 _set_error: _set_err code: 2, str: Couldn't open remote file 'test.txt': No such file. #8888 1319651554.00000 open: new remote file 'test.txt' open, rid: #8888 1319651554.00000 _rel2abs: 'test.txt' --> 'test.txt' #8888 1319651554.00000 _queue_msg: queueing msg len: 17, code:13, id:7 ... 1 00 00 00 11 0d 00 00 00 07 00 00 00 08 74 65 73 74 2e 74 78 74 | .............test.txt #8888 1319651554.00000 _get_msg: waiting for message... 1 #8888 1319651554.00000 _do_io: _do_io connected: 1 #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io write queue: 21, syswrite: 21, max: 65536, $!: 00 00 00 11 0d 00 00 00 07 00 00 00 08 74 65 73 74 2e 74 78 74 | .............test.txt #8888 1319651554.00000 _do_io: _do_io select(-,-,-, undef) #8888 1319651554.00000 _do_io: _do_io read sysread: 36, total read: 36, $!: 00 00 00 20 65 00 00 00 07 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 | ... e............No such file... 00 02 65 6e | ..en #8888 1319651554.00000 _get_msg: got it!, len:32, code:101, id:7, status: 2 65 00 00 00 07 00 00 00 02 00 00 00 0d 4e 6f 20 73 75 63 68 20 66 69 6c 65 2e 00 00 00 02 65 6e | e............No such file.....en #8888 1319651554.00000 _set_status: _set_status code: 2, str: No such file. #8888 1319651554.00000 _set_error: _set_err code: 21, str: Couldn't delete remote file: No such file. #8888 1319651554.00000 DESTROY: Net::SFTP::Foreign=HASH(0x15ee3c)->DESTROY called (current pid: 8888, disconnect_by_pid: ) #8888 1319651554.00000 disconnect: Net::SFTP::Foreign=HASH(0x15ee3c)->disconnect called (ssh pid: 8892) #8888 1319651554.00000 _conn_lost: _conn_lost

      I'm not sure how to post the output any better. Sorry it's kind of messy.

        Include the output inside code tags: <code>...</code>. Otherwise it is impossible to follow it.