Posted on 2006-05-11 17:48:46-07 by mnagaraj
Error in Net:FTP v2.75 ---works in v2.56
I have isolated the following problem in version 2.75. It seems to work just fine in 2.56. Any ideas on how to avoid this in v2.75.

This is the link from Google Groups where I had posted it before finding out the version issue:

http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/61783edf2b17f464/528e48abc46040a2#528e48abc46040a2

Thanks,

-mouli

Mouli Nagarajan

<code>

#!/usr/local/bin/perl_5.6.1

use strict;
use warnings;
use Net::FTP;

my $firm_user = ' user@anonymous.com';
my $firm_pass = 'password';
my $firm_dir = "upload";
my $outfile = "a";

print "Outfile: $outfile\n";

#Open a socks FTP connection
my $ftp = Net::FTP->new('socks', Debug => 1);

$ftp->login($firm_user, $firm_pass)
or die "ERROR! Unable to connect to the FTP server: ". $ftp->message;

$ftp->pasv();

#set the mode to ascii
$ftp->ascii();

#all uploaded files are to be placed in the "upload" directory
$ftp->cwd($firm_dir)
or die "ERROR! Unable to 'cd' to 'upload' directory: ". $ftp->message;

print $ftp->ls();

#put the outfile just created
$ftp->put($outfile)
or die "ERROR! Unable to ftp the file at this time: ". $ftp->message;

$ftp->quit;

print "$outfile was successfully sent via FTP to confirmIt.\n";

### End of FTP

</code>


<STDOUT>

Outfile: a
Net::FTP>>> Net::FTP(2.75)
Net::FTP>>> Exporter(5.562)
Net::FTP>>> Net::Cmd(2.26)
Net::FTP>>> IO::Socket::INET(1.25)
Net::FTP>>> IO::Socket(1.26)
Net::FTP>>> IO::Handle(1.21)
Net::FTP=GLOB(0x31d40)<<< 220 Secure Gateway FTP server
Net::FTP=GLOB(0x31d40)>>> user user@anonymous.com
Net::FTP=GLOB(0x31d40)<<< 331-Connected to anonymous.com
Net::FTP=GLOB(0x31d40)<<< 331-(vsFTPd 1.2.1)
Net::FTP=GLOB(0x31d40)<<< 331 Please specify the password.
Net::FTP=GLOB(0x31d40)>>> PASS ....
Net::FTP=GLOB(0x31d40)<<< 230 Login successful.
Net::FTP=GLOB(0x31d40)>>> PASV
Net::FTP=GLOB(0x31d40)<<< 227 Passive mode entered (69,52,64,222,186,114)
Net::FTP=GLOB(0x31d40)>>> TYPE A
Net::FTP=GLOB(0x31d40)<<< 200 Switching to ASCII mode.
Net::FTP=GLOB(0x31d40)>>> CWD pub/incoming
Net::FTP=GLOB(0x31d40)<<< 250 Directory successfully changed.
Net::FTP=GLOB(0x31d40)>>> PORT 69,52,99,54,137,32
Net::FTP=GLOB(0x31d40)<<< 200 PORT command successful. Consider using PASV.
Net::FTP=GLOB(0x31d40)>>> NLST
Net::FTP=GLOB(0x31d40)<<< 150 Here comes the directory listing.
Net::FTP=GLOB(0x31d40)<<< 226 Directory send OK.
Net::FTP=GLOB(0x31d40)>>> ALLO 16
Net::FTP=GLOB(0x31d40)<<< 202 ALLO command ignored.
Net::FTP=GLOB(0x31d40)>>> PORT 69,52,99,54,137,35
Net::FTP=GLOB(0x31d40)<<< 530 Bad command sequence
ERROR! Unable to ftp the file at this time: Bad command sequence

</STDOUT>

Direct Responses: 3861 | 3862 | 3933 | Write a response
Posted on 2006-12-20 23:20:22-08 by timhood in response to 2282
Re: Error in Net:FTP v2.75 ---works in v2.56
Did you ever find a resolution to this issue? We are seeing similar results with a particular connection, with either 2.72 or 2.74. The interesting thing is that the remote server is a Microsoft FTP server but if one connects manually using the ftp command, one can repeat the same commands and successfully store a file. But using Net::FTP, it fails whether Passive is true or false.
Direct Responses: Write a response
Posted on 2006-12-20 23:22:46-08 by timhood in response to 2282
Re: Error in Net:FTP v2.75 ---works in v2.56
Did you ever find a resolution to this issue? We are seeing similar results with a particular connection, with either 2.72 or 2.74. The interesting thing is that the remote server is a Microsoft FTP server but if one connects manually using the ftp command, one can repeat the same commands and successfully store a file. But using Net::FTP, it fails whether Passive is true or false.
Direct Responses: Write a response
Posted on 2006-12-30 03:55:06-08 by magnificenttears in response to 2282
Re: Error in Net:FTP v2.75 ---works in v2.56
I was doing this at thirty remote locations and one of the locations had this same problem.
The key responses to note in the Net::FTP Debug output are "220 Secure Gateway FTP Server" and "530 Bad Command Sequence".
The "Gateway" appears to be acting like a proxy between the client and server. It is the choice of this proxy to improperly reject what it doesn't like, instead of simply passing legitimate requests through to the server you actually intended to contact.
This "Gateway" does not agree on the order of the commands chosen by Net::FTP for a *put* command.
Specifically it does not appreciate ALLO followed by PASV; it only accepts the PASV to come first (substitute PORT for PASV if you prefer).

My hack to circumvent this 1 machine (out of 30) was to remove the ALLO comand by pretending that it already happened:
$ftp->binary; ${*$ftp}{net_ftp_allo} = 1 if( $dumb_gateway ); # AAAAAAAAHHHHHHHHHHHHHHHHHHH!!!!!! $ftp->put( $local_file, $remote_file );
For further explanation I will refer you to the Net/FTP.pm source.

(incoming opinion:) I will consider this "Gateway" to be stupid, or at the very least, to have a bug. I find it perfectly logical to put the allocation request first, for if the server would deny such allocation, the server would not have to open and listen to a port for the incoming storage command. Resources would be saved. I will also note that while the "Gateway" responds to any further command with "530 Bad Command Sequence", rfc959, as well as dozens of googleable sites on the internet will rightfully list 530 as an Authentication failure (Not Logged In, note the x3z pattern), and 503 as a syntax error (Bad Command Sequence, x0z). So to reiterate, this "Gateway" is dumb.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.