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

Any ideas why I am getting a "File open error = 13" error with my get? The file consists of 20 numbers on each line, with about 1,000 lines in the file. Below is the code, with some of the specifics changed for obvious reasons.
use strict; use warnings; use Net::FTP; my $directory = "the directory"; my $ftp; $ftp = Net::FTP->new("1.1.1.1", Debug => 0) || die "Cannot connect to 1.1.1.1: $@"; $ftp->login("user",'pass') || die "Cannot login ", $ftp->message; $ftp->binary(); $ftp->get("$directory.thedir","C:\\temp\\ftp") || die "get failed ", $ftp->message; $ftp->quit;

Replies are listed 'Best First'.
Re: File Open Error = 13?
by BrowserUk (Patriarch) on Oct 28, 2009 at 20:16 UTC

    You can work out what that error number means easily:

    C:\test>perl -le"$!=13; print $!" Permission denied

    Which strongly suggests that the userid you're using doesn't have permission to access the required file.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks!! That is strange as I use that userID/pass in FileZilla without any issues. I'll need to dig deeper.
        It's a *local* permission issue. You don't have permission to overwrite file C:\temp\ftp
Re: File Open Error = 13? (remote)
by tye (Sage) on Oct 29, 2009 at 01:09 UTC

    It appears that most of the answers in this thread are based on an invalid assumption. Looking at the source for the message() method (in the Net::Cmd source code), it doesn't return a local error and the number 13 doesn't appear to have anything to do with $! on the local host.

    If it had been an error opening the local file, then the reaction would have been the following code from get() in Net::FTP source code:

    carp "Cannot open Local file $local: $!\n";

    So "File open error = 13" is the response coming back from the remote FTP server. 13 being the defined value for EACCES is common enough that it still might indicate "permission denied" but it would depend on whether the remote FTP server is actually reporting errno and what errno of 13 means on that system (not what your local system reports $! = 13 as being).

    You might want to report $ftp->code(), a 3-digit status code that you can look up, for example, in http://help.globalscape.com/help/support/Error_Codes/FTP_Codes.htm.

    - tye        

      Thanks tye, I used $ftp->code() and get a 553 error which means the file name is not allowed. The file name is "ALL2EXT". It does not have an extension, but I don't think perl cares, and I don't see anything wrong with the file name.

        I don't see how "$director­y.thedir" could expand to "ALL2EXT". In your example, it would expand to "the directory.thedir", which certainly might not be "allowed". You might want to dump the filename to make sure it is really what you think it is.

        - tye