Not a question per se but it might save somebody some hair. If anybody can elaborate on why this happens I'd appreciate it.

When using Net::FTP to list remote ftp directories. The FTP module returns an object undefined in Net::Cmd if the remote directory is empty. This seems to happen with some servers and not others.

What I've found is that when executing an ls() on an empty directory, some servers will return a 250 status code indicating that a non terminal error has occured. This is fine. Some "other servers" will return a 500 status error which seems to cause the Net::Cmd to disconnect the session and undef the object leaving the caller to catch it in an eval.

I believe that the servers should return 2x0 regardless of the connection type as it's not a fatal error.

The "other servers" behave differently depending on whether the connection is passive or non-passive. Under a passive connection I got a 500 and crashed but when connecting non-passively the same "other server" returned a 250 as expected.

What made it hard to find was that I was not implicitly setting a passive connection and the scripts behaviour was changing between the dev and production environments. The answer has been to implicitly set the PASSIVE parameter in the script and never to assume that the default is consistent.


In reply to ls() on empty directory causes error in Net::FTP by steved

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.