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

Hello Monks,
I am trying a simple file upload, and am only getting a 0-byte file at the destination. Code and debug log:
my $ftp = Net::FTP->new("my.ftp.server", Debug => 1, Passive => 1) or +return; $ftp->login("myuser","mypass") or return; $ftp->cwd($dir) or $ftp->mkdir($dir, 1); $ftp->cwd($dir) or return; $ftp->binary; $ftp->put($file) or return; $ftp->quit or return;
The FTP server is pure-ftpd on Linux, and of course I have tested it to work with other clients
>>> USER myuser <<< 331 User myuser OK. Password required >>> PASS .... <<< 230-User myuser has group access to: 100 33 16 <<< 230 OK. Current directory is / >>> CWD /temp/ <<< 250 OK. Current directory is /temp >>> CWD /temp/ <<< 250 OK. Current directory is /temp >>> TYPE I <<< 200 TYPE is now 8-bit binary >>> ALLO 1800 ^^ this is the correct file size <<< 200 dc.w $4E71 >>> PASV <<< 227 Entering Passive Mode (1,2,3,4,117,65) >>> STOR New Text Document (2).txt <<< 150 Accepted data connection <<< 226 File successfully transferred >>> QUIT <<< 221-Goodbye. You uploaded 0 and downloaded 0 kbytes. ^^ 0 bytes?! <<< 221 Logout.

Replies are listed 'Best First'.
Re: found a bug in Net::FTP?
by runrig (Abbot) on Sep 30, 2009 at 16:05 UTC
    "or return;" doesn't tell you much about what went wrong, if Net::FTP has anything to tell you. On the call to new, use "or die $@;", and on all other calls, use "or die $ftp->message();".
Re: found a bug in Net::FTP?
by Illuminatus (Curate) on Sep 30, 2009 at 00:35 UTC
    Is there a reason you need to use passive mode? When you tested other clients, did you test them in passive mode?
      It was not the cause. Sorry for not being complete, but I really didn't think this had anything to do with it: I was testing first if the file was complete with
      flock($f, LOCK_EX) or return; #file in use
      apparently I must do a flock($f, LOCK_UN); although the transfer was in the same procedure, one line below. I don't understand why..