View Single Post
  #1 (permalink)  
Old February 25th, 2009, 05:34 PM
vuorela vuorela is offline
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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:

Code:
telnet 192.168.18.237 21
Trying 192.168.18.237...
Connected to 192.168.18.237.
Escape character is '^]'.
220 ProFTPD 1.3.0 Server (Debian) [192.168.18.237]
user USERNAME
331 Password required for USERNAME.
pass PASSWORD
230 User USERNAME logged in.
port 192,168,18,129,195,84
200 PORT command successful
list
150 Opening ASCII mode data connection for file list
226 Transfer complete.
quit
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.

Code:
#!/usr/bin/perl

$addr='192.168.18.237';
$port='21';

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";
close($com_sock);
And the output:
Code:
220 ProFTPD 1.3.0 Server (Debian) [192.168.18.237]
331 Password required for USERNAME.
230 User USERNAME logged in.
after which the program hangs.

Any recommendations would be great. Thanks.
Reply With Quote