Problems with binary transfers in Net::FTP
[email protected] Mon, 24 Feb 2003 11:27:56 +0100
| Newsgroups | perl.libnet |
|---|---|
| Message-ID | <3E5A01BC.17292.867471@localhost> |
I am writing a perl script to automatically transfer a section of
our Intranet to Internet, at the same time reformatting index
pages and rearranging directories. I am rather satisfied of the
outcome, but I have problems with the transfer of TIFF images:
apparently, they are transferred in ASCII mode, in spite of the
message "Opening BINARY data mode" in the log.
Here is a test script I used to narrow down the problem (sorry
for the masking of the addresses, even if we don't have an
explicit policy to that effect I think it's safer to avoid
sending them out):
-----<Cut here>-----
#!/usr/bin/perl -w
$debug = 1 ;
$localfile = "test.tif" ;
$remotefile = "test-auto.tif" ;
use Net::FTP ;
use Fcntl ;
$ftp = Net::FTP -> new ( "xxx.yyy.z.ww" ,
Debug => $debug , Passive => 0
) ;
if ( ! defined $ftp ) {
print "Error: connection to the FTP server failed.\n" ;
print "Reason: $@\n" ;
exit 1 ;
}
$ftp -> login ( "xxxxxxxxxxxx" , "************" ) ;
if ( ! $ftp -> ok () ) {
print "Error connecting to the FTP server.\n" ;
$errortext = $ftp -> message ;
print "Reason: $errortext</p>\n" ;
exit 1 ;
}
$ftp -> cwd ( "xxx.xxxxxx.it/ProjectTest/ ) ;
# $ftp -> type ( "binary" ) ;
$ftp -> quot ( "TYPE" , "I" ) ;
$ftp -> put ( $localfile , $remotefile ) ;
# $dcref = $ftp -> stor ( $remotefile ) ;
# sysopen ( LOC , $localfile , O_RDONLY ) ;
# binmode LOC ;
# my $readbuf = '' ;
# my $nread = 0 ;
# my $bsize = 1024 ;
# while ( ( $nread = sysread ( LOC , $readbuf , $bsize ) ) != 0 )
{
# $dcref -> write ( $readbuf , $nread ) ;
# }
# $dcref -> close ;
# close LOC ;
$ftp -> quit ;
-----<Cut here>-----
The (NT) server I am connecting to does not understand "TYPE
BINARY", so I have to send a "TYPE I" command instead. In the
commented section I tried to use a dataconn object to have more
control. I also tried to turn passive mode on, since the server
seems to prefer passive data transfer. The result is always the
same: the file transferred via manual ftp is correctly sent,
while the one transferred via Net:FTP gets corrupted.
And here is the output:
-----<Cut here>-----
Net::FTP: Net::FTP(2.65)
Net::FTP: Exporter(5.566)
Net::FTP: Net::Cmd(2.21)
Net::FTP: IO::Socket::INET(1.26)
Net::FTP: IO::Socket(1.27)
Net::FTP: IO::Handle(1.21)
Net::FTP=GLOB(0x806517c)<<< 220 InterScan FTP VirusWall NT 3.53
(Stand-alone Mode), Virus scan on
Net::FTP=GLOB(0x806517c)>>> user [email protected]
Net::FTP=GLOB(0x806517c)<<< 331 Password required for
xxxxxxxxxxxx.
Net::FTP=GLOB(0x806517c)>>> PASS ....
Net::FTP=GLOB(0x806517c)<<< 230 User xxxxxxxxxxxx logged in.
Net::FTP=GLOB(0x806517c)>>> CWD xxx.xxxxxx.it/ProjectTest/
Net::FTP=GLOB(0x806517c)<<< 250 CWD command successful.
Net::FTP=GLOB(0x806517c)>>> TYPE I
Net::FTP=GLOB(0x806517c)<<< 200 Type set to I.
Net::FTP=GLOB(0x806517c)>>> PORT xx,yyy,w,zz,14,24
Net::FTP=GLOB(0x806517c)<<< 200 PORT command successful.
Net::FTP=GLOB(0x806517c)>>> STOR test.tif
Net::FTP=GLOB(0x806517c)<<< 150 Opening BINARY mode data
connection for test.tif.
Net::FTP=GLOB(0x806517c)<<< 226-Message from InterScan FTP
VirusWall NT 3.53
Net::FTP=GLOB(0x806517c)<<< 226-No virus found in test.tif
Net::FTP=GLOB(0x806517c)<<< 226 Transfer complete.
Net::FTP=GLOB(0x806517c)>>> QUIT
Net::FTP=GLOB(0x806517c)<<< 221
-----<Cut here>-----
Everything seems just fine, doesn't it? Well it isn't; here is an
ftp session which demonstrates it:
-----<Cut here>-----
$ ftp xxx.yyy.z.ww
Connected to xxx.yyy.z.ww (xxx.yyy.z.ww).
220 InterScan FTP VirusWall NT 3.53 (Stand-alone Mode), Virus
scan on
331 Password required for xxxxxxxxxxxx.
230 User xxxxxxxxxxxx logged in.
Remote system type is Windows_NT.
ftp> cd xxx.xxxxxx.it/ProjectTest/
250 CWD command successful.
ftp> bin
200 Type set to I.
ftp> put test.tif
local: test.tif remote: test.tif
227 Entering Passive Mode (xxx,yyy,z,ww,10,47)
125 Data connection already open; Transfer starting.
226-Message from InterScan FTP VirusWall NT 3.53
226-No virus found in test.tif
226 Transfer complete.
110180 bytes sent in 0.325 secs (3.3e+02 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (xxx,yyy,z,ww,10,63)
125 Data connection already open; Transfer starting.
02-24-03 10:58AM 110494 test-auto.tif
02-24-03 11:12AM 110180 test.tif
226 Transfer complete.
ftp> quit
221
$ wc -l test.tif
314 test.tif
-----<Cut here>-----
As you can see from the output of "wc", the tif "file" has 314
"lines", so that an additional octet is added for each "line", as
in ASCII mode.
Sorry for the length, I tried to be as precise as possible. Any
suggestion is HIGHLY welcome...
Francesco Marchetti-Stasi
(f.marchettistasi at avlp.it)