Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Answer: Net::FTP get problem

by rob_au (Abbot)
on Jun 18, 2002 at 06:48 UTC ( #175295=categorized answer: print w/replies, xml ) Need Help??

Q&A > network programming > Net::FTP get problem (unexpected EOF) - Answer contributed by rob_au

While there's not quite enough here for me to be sure, my strong guess is that you are experiencing the same problem as described here - If indeed, you are facing the same issue, it is the result of not so much your script, but your network configuration and specifics of the FTP protocol.

When connecting to a FTP server, two socket streams are used for communications - The first is the control connection initiated by your FTP client between which the FTP client and server exchange commands and replies (TCP socket 21). The second is a full-duplex connection over which data is transferred in a specified mode and type. The data transferred may be part of a file, an entire file or a listing of files within a directory. Typically, this data port is the port adjacent to the control port (TCP socket 20).

In general, it is the FTP server's responsibility to initiate and maintain the data connection. It is here that your script is running into problems.

This host address, along with the preferred socket for data communications, are sent to the server via the PORT command. I suspect that you are in fact connecting to a live Internet host with this script through a network firewall or layer of address translation and as such, the data connection from the server to your machine is failing because the FTP server is unable to reach your private machine.

The means by which to fix this is to switch to passive FTP transfer mode via the PASV command - This command changes the default behaviour of data port negotiation, shifting the onus for responsibility for data port establishment and maintenance back to the client. This allows the client to control its only data connection through the network firewall or translation layer, allowing normal FTP communications to occur. eg.

use Net::FTP; # Passive mode can be set with object initiation my $ftp = Net::FTP->new( $hostname, Debug => 1, Passive => 1 ) or die +$!; $ftp->login( $user, $password ); # Or with $object->pasv; $ftp->pasv;

Further information on this topic can be found in RFC documents (0959) File Transfer Protocol, (1122) Requirements for Internet hosts - communication layers and (1579) Firewall-Friendly FTP.

Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2018-03-19 05:25 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (232 votes). Check out past polls.