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!

In reply to Net::SFTP::Foreign stat Error by csftpteam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.