Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Answer: Net::FTP get problem

( #175295=categorized answer: print w/ replies, xml ) Need Help??

Q&A > network programming > Net::FTP get problem (unexpected EOF) 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.

Comment on Answer: Net::FTP get problem
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-12-26 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls