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

OK, I'm stumped.

I've got a short routine that logs onto a ftp server using Net::ftp from a Win98 box and uploads an html file. All goes well, except that only about 3/4 of the file actually makes it.

The code is quite simple:
my $ftp = Net::FTP->new($destserv) or die "error connecting\n"; $ftp->login($destuser,$destpass); $ftp->cwd('/path/to/proper/directory'); $ftp->put($output_file) or die "error uploading\n"; $ftp->quit();
The cut-off is always at the same point, so I'm guessing I'm missing some parameter or other. I would have thought that a failure to complete the upload would trigger the error message I specified via die, but it does not. Can anyone point me towards a solution? Thanks for your time.

Replies are listed 'Best First'.
Re: Truncated upload using Net:ftp
by derby (Abbot) on Aug 29, 2001 at 00:19 UTC
    Instead of binmode you can set the type within ftp. You might also want to set the Debug flag to watch what's going on

    my $ftp = Net::FTP->new($destserv, Debug => 1) or die "error connecting\n"; $ftp->login($destuser,$destpass); $ftp->cwd('/path/to/proper/directory'); $ftp->binary(); $ftp->put($output_file) or die "error uploading\n"; $ftp->quit();

    -derby

Re: Truncated upload using Net:ftp
by LD2 (Curate) on Aug 28, 2001 at 23:22 UTC
    Are you using binmode() at all? That may be part of the problem.

    Update: Did you try using Debug as derby suggested? If so, what were the errors? Also, there is a note that mentions if you use ASCII transfers - NOTE: The size reported is the size of the stored file on the remote server. If the file is subsequently transfered from the server in ASCII mode and the remote server and local machine have different ideas about ``End Of Line'' then the size of file on the local machine after transfer may be different. I'm not sure if that would affect it or not.
      LD2,

      I'm afraid not. Your suggestion did lead me to make sure that the upload was done in ASCII mode with
      $ftp->ascii();
      but that did not help. The upload stops at the exact same spot.

      Back to the drawing board...
Re: Truncated upload using Net:ftp
by cLive ;-) (Prior) on Aug 29, 2001 at 00:25 UTC
    Do you need to do passive transfers?

    If so, read this

    cLive ;-)

      Thanks everyone for your input.

      I tried a passive transfer with no luck. Setting Debug=>1 shows that the exchange between my script and the ftp server proceeds normally. The only difference is that only 69,631 of the file's 73,682 bytes are transferred. When I upload the same file manually (via the DOS prompt) the complete file is transferred. Very odd!

      I realize we're drifting away from pure perl but any other suggestions would be greatly appreciate.

      best,
      sz
        This is the part where I admit to an embarrassing oversight.

        I finally traced the bug to a subtle buffering problem. The file being uploaded is not fully written at the time that it is ftp'ed. I never noticed because by the time the ftp is completed and I check the local copy of the file, the buffer has been written to disk. Once I explicitly close (FH) prior to uploading the file, my problem goes away.

        On the bright side, I learned a lot more about Net::ftp.

        Thanks again everyone!
        sz