Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am able to successfully ftp the below files,but the thing is the sizes of the files are not at all right?what am I missing?is there any mode I need to set before copying?

#!/usr/bin/perl -w use strict; use warnings; use Net::Telnet; use Net::FTP; my $ftp = Net::FTP->new("192.168.0.1", Debug => 0) or die "Cannot connect to the target: $@"; $ftp->login("root","root") or die "Cannot login ", $ftp->message; $ftp->cwd("/mnt/files") or die "Cannot change working directory ", $ftp->message; $ftp->put("data.mbn") or die "put failed ", $ftp->message;; $ftp->put("image.elf") or die "put failed ", $ftp->message; $ftp->quit();

Replies are listed 'Best First'.
Re: Sizes of copied files are not right
by roboticus (Chancellor) on Apr 21, 2011 at 18:03 UTC

    You may just need to add $ftp->binary(); before sending the files over. Otherwise it may be using text mode which may translate your \n to \r\n or vice versa.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Sizes of copied files are not right
by mikeraz (Friar) on Apr 21, 2011 at 18:02 UTC

    The default file transfer type is ASCII. If the line endings are different on your two system (Unix vs Win for example) all occurrences of newline will be converted.

    Your file types appear to be binary data - not text files. Stting the file transfer mode to bin will address this issue.


    Be Appropriate && Follow Your Curiosity

      how do i set that?

        As roboticus stated, the command (given your example code) would be $ftp->binary; the Net::FTP manpage explains this.


        Be Appropriate && Follow Your Curiosity