Net::FTP - Binary mode

Discussion in 'Perl Misc' started by Pascal, Nov 13, 2005.

  1. Pascal

    Pascal Guest

    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
    Pascal, Nov 13, 2005
    #1
    1. Advertising

  2. "Pascal" <> wrote in
    news:437742d5$0$11254$:

    > 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.

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Nov 13, 2005
    #2
    1. Advertising

  3. A. Sinan Unur wrote:
    > "Pascal" <> wrote in
    > news:437742d5$0$11254$:
    >
    > > 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?



    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.
    it_says_BALLS_on_your forehead, Nov 14, 2005
    #3
  4. "it_says_BALLS_on_your forehead" <> wrote in
    news::

    > A. Sinan Unur wrote:
    >> "Pascal" <> wrote in
    >> news:437742d5$0$11254$:
    >>
    >> > 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?

    >
    >
    > 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:

    >> > 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.


    Sinan
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Nov 14, 2005
    #4
  5. A. Sinan Unur wrote:
    > "it_says_BALLS_on_your forehead" <> wrote in
    > news::
    >
    > > A. Sinan Unur wrote:
    > >> "Pascal" <> wrote in
    > >> news:437742d5$0$11254$:
    > >>
    > >> > 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?

    > >
    > >
    > > 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.


    yes, correctness comes first, *then* efficiency. this (apparently
    UN)common sense should be stamped on every posting.
    it_says_BALLS_on_your forehead, Nov 14, 2005
    #5
  6. Pascal

    Guest

    Pascal wrote:
    > 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.
    , Nov 14, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John J Lee
    Replies:
    3
    Views:
    455
    bruno at modulix
    Dec 1, 2005
  2. Edward Loper
    Replies:
    0
    Views:
    444
    Edward Loper
    Aug 7, 2007
  3. John J Lee
    Replies:
    0
    Views:
    501
    John J Lee
    Aug 7, 2007
  4. Edward Loper

    mmm-mode, python-mode and doctest-mode?

    Edward Loper, Aug 9, 2007, in forum: Python
    Replies:
    0
    Views:
    414
    Edward Loper
    Aug 9, 2007
  5. D. Buck
    Replies:
    2
    Views:
    458
    D. Buck
    Jun 29, 2004
Loading...

Share This Page