Net::FTP - Binary mode

P

Pascal

Hi All,

I get an issue by using Net::FTP to transfer both text and binary files from
an Unix server to a PC under Windows 2000. For that, I'm using the
Net::FTP::Get() function.

The files are transferred to the PC but some characters 'OD' are added into
the binary files. However, I've well activated the binary mode by
Net::FTP::Binary().

Below is an extract of my code:
my $opt_s = "myserver";
my $opt_u = "mylogin";
my $opt_p = "mypassword";
my $opt_r = "myremotedir";

$ftp = new Net::FTP ( $opt_s );
die "Failed to connect to server '$opt_s': $!\n" unless $ftp;

die "Failed to login as $opt_u\n" unless $ftp->login($opt_u, $opt_p);

warn "Failed to set binary mode\n" unless $ftp->binary();

print "Cannot change directory to $opt_r\n" unless $ftp->cwd($opt_r);
die "Failed to GET $l\n" unless $ftp->get("file.bin",
"$localdir/file.bin");
$ftp->quit if( defined($ftp) );

I don't get idea about how I can solve my problem. Could you help me ? Is
this problem a know bug from Net::FTP ?

Thanks very much for your help.
BRgds
Pascal
 
A

A. Sinan Unur

I get an issue by using Net::FTP to transfer both text and binary
files
....

warn "Failed to set binary mode\n" unless $ftp->binary();

Then why are you transferring both types of files as binary?

Sinan

PS: Please read the posting guidelines for this group. In particular,
don't retype parts of script. Instead, create a short but complete script
others can run. Then, post that.
 
I

it_says_BALLS_on_your forehead

A. Sinan Unur said:
Then why are you transferring both types of files as binary?


not sure if this is why the OP chose to transfer in binary mode, but
from CPAN docs on Net::FTP...

binary
Transfer file in binary mode. No transformation will be done.

Hint: If both server and client machines use the same line ending for
text files, then it will be faster to transfer all files in binary
mode.
 
A

A. Sinan Unur

not sure if this is why the OP chose to transfer in binary mode, but
from CPAN docs on Net::FTP...

binary
Transfer file in binary mode. No transformation will be done.

Hint: If both server and client machines use the same line ending for
text files, then it will be faster to transfer all files in binary
mode.

Of course, if the server and client machines do not use the same line
ending for text files, then the files will be transferred incorrectly.

From the original post:

Sinan
 
I

it_says_BALLS_on_your forehead

A. Sinan Unur said:
Of course, if the server and client machines do not use the same line
ending for text files, then the files will be transferred incorrectly.

yes, correctness comes first, *then* efficiency. this (apparently
UN)common sense should be stamped on every posting.
 
U

usenet

Pascal said:
I get an issue by using Net::FTP...

This is one reason why I try to use Net::SFTP whenever I can (I never
need to worry about line endings, etc). The other advantage is
certificate-based authentication (which helps me avoid having passwords
visible in my scripts or needing to fool with external password files,
etc - and won't let anyone "sniff" my password on the network). And, of
course, it is virtually impossible to have a corrupted SFTP file
transfer.

The protocol, of course, carries encryption overhead, so throughput
will not be as fast. This is a price I am willing to pay.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top