Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Net::FTP Unexpected EOF

by SiN8 (Initiate)
on Jan 10, 2002 at 06:19 UTC ( #137654=perlquestion: print w/replies, xml ) Need Help??
SiN8 has asked for the wisdom of the Perl Monks concerning the following question:

Here's my code:
use Net::FTP; my $hostname="hostname"; my $user="user"; my $password="pass"; $ftp=Net::FTP -> new("$hostname",Debug=>1) or die ("Connect failed"); $ftp->login("$user","$password"); $ftp->binary; $ftp->put("filename.ext")
Here's the output:
Net::FTP: Net::FTP(2.62) Net::FTP: Exporter Net::FTP: Net::Cmd(2.20) Net::FTP: IO::Socket::INET Net::FTP: IO::Socket(1.1603) Net::FTP: IO::Handle(1.1505) Net::FTP=GLOB(0x81b3320)<<< 220 Server ready. Net::FTP=GLOB(0x81b3320)>>> user user Net::FTP=GLOB(0x81b3320)<<< 331 Password required for user. Net::FTP=GLOB(0x81b3320)>>> PASS .... Net::FTP=GLOB(0x81b3320)<<< 230 User user logged in. Net::FTP=GLOB(0x81b3320)>>> TYPE I Net::FTP=GLOB(0x81b3320)<<< 200 Type set to I. Net::FTP=GLOB(0x81b3320)>>> PORT 10,1,4,49,219,108 Net::FTP: Unexpected EOF on command channel at script.cgi line 37
What does the EOF mean here? It also occurs for $ftp->ls(). How can I fix this?

Replies are listed 'Best First'.
Re: Net::FTP Unexpected EOF
by rob_au (Abbot) on Jan 10, 2002 at 09:33 UTC
    Your problem here resides not so much with your script but with 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.

    According to the output supplied, it appears you are attempting to connect to the FTP from a machine with a private class address of - 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.


    perl -e 's&&[@.]/&&s&.com.&_&&&print'

Re: Net::FTP Unexpected EOF
by grep (Monsignor) on Jan 10, 2002 at 08:31 UTC
    You have 2 connections when you FTP, a command channel and a data channel. The server daemon will timeout a particular channel if it has not seen data in a while. Unfortunately that means if the daemon has a timeout of 5 minutes and your download takes 6 the command channel (which has seen no data) will shutdown after 5 minutes of the upload. The data channel will not timeout (for obvious reasons).

    So to make a long answer short: increase the timeout of the daemon.

    <stong>BTW: if you want to read a more detailed explaination this link will help.

    grep> cd pub grep> more beer

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://137654]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-02-24 23:19 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (364 votes). Check out past polls.