Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 25th, 2009, 05:34 PM
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
  #2 (permalink)  
Old March 4th, 2009, 11:15 PM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile 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.

Last edited by vuorela; March 4th, 2009 at 11:18 PM.
Reply With Quote
  #3 (permalink)  
Old April 21st, 2009, 12:47 PM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Code:
$com_sock->autoflush();
?
__________________
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sockets & Multithreading Rosicky Java Basics 1 March 15th, 2007 01:18 PM
Sockets Geo121 General .NET 1 March 30th, 2006 10:12 AM
Sockets riteshu C++ Programming 1 September 22nd, 2004 03:30 AM
Sockets natmaster Java GUI 2 April 26th, 2004 09:40 PM
Sockets idplatt BOOK: Beginning Java 2 1 August 14th, 2003 11:33 AM



All times are GMT -4. The time now is 02:36 PM.


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