p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Perl (http://p2p.wrox.com/forumdisplay.php?f=196)
-   -   help with perl sockets and ftp (http://p2p.wrox.com/showthread.php?t=72950)

vuorela February 25th, 2009 05:34 PM

help with perl sockets and ftp
Thank you for reading this thread.

I need to make a simple ftp client using Perl for an assignment and I am having some troubles. I have made a small program which illustrates my first problem. I believe that it is a I/O synchronization issue but am not sure.

First here is what happens when I use telnet:


telnet 21
Connected to
Escape character is '^]'.
220 ProFTPD 1.3.0 Server (Debian) []
331 Password required for USERNAME.
230 User USERNAME logged in.
port 192,168,18,129,195,84
200 PORT command successful
150 Opening ASCII mode data connection for file list
226 Transfer complete.
221 Goodbye.
Connection closed by foreign host.

I have an active data server that correctly gets the output of the LIST command.

The problem that I am having is when I try to do the same communication using Perl and sockets. I have broken my code down to make look as close as possible to the telnet version.




use IO::Socket;

my $com_sock = new IO::Socket::INET (
                                PeerAddr => $addr,
                                PeerPort => $port,
                                Proto => 'tcp',

die "Could not create socket: $!\n" unless $com_sock;

$temp = <$com_sock>;
print $temp;

print $com_sock "user USERNAME\n";
$temp = <$com_sock>;
print $temp;

print $com_sock "pass PASSWORD\n";
$temp = <$com_sock>;
print $temp;

print $com_sock "port 192,168,18,129,195,84\n";
$temp = <$com_sock>;
print $temp;

print $com_sock "list\n";
$temp = <$com_sock>;
print $temp;
$temp = <$com_sock>;
print $temp;

print $com_sock "quit\n";

And the output:

220 ProFTPD 1.3.0 Server (Debian) []
331 Password required for USERNAME.
230 User USERNAME logged in.

after which the program hangs.

Any recommendations would be great. Thanks.

vuorela March 4th, 2009 11:15 PM

After several hours of reading about ftp.......
A friend of mine ran into the same problem and figured it out. It turns out this had a really simple solution.

The line endings in FTP must be "\r\n" like in windows, even though I am programming on a Linux box and communicating to another Linux box.

The really annoying part is that only the PORT command seems to care what the line endings are.

Well I hope this little bit of information can help someone else in the future.

ciderpunx April 21st, 2009 11:47 AM



All times are GMT -4. The time now is 08:56 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.