1
use Net::FTP;

$ftp = Net::FTP->new($host) or die "Cannot connect to $host: $@";
$ftp->binary;
$ftp->login($user, $pass) or die "Cannot login: ", $ftp->message;
$ftp->cwd("downloads") or die "Cannot change working directory to downloads: ", $ftp->message;
@ls = $ftp->ls;
if (@ls)
{
    $ftp->get($ls[0]) or warn "Cannot get $ls[0]: ", $ftp->message;
    $ftp->delete($ls[0]) or warn "Cannot delete $ls[0]: ", $ftp->message;;
}
$ftp->quit;

When I run the above code which connects to an FTP server of a remote host, it tries to get a PDF file in the downloads directory, but the PDF file transferred is 8 bytes less in size than the original file, so it doesn't open properly in a PDF reader.

Is there something I am not doing correctly? The FTP server is vsftpd on Ubuntu.

CJ7
  • 22,579
  • 65
  • 193
  • 321
  • 2
    CRLF→LF translation fixed by `->binary()`? – ikegami Jul 14 '20 at 07:28
  • @ikegami I fixed it by putting `->binary()` after the login instead of before. – CJ7 Jul 14 '20 at 07:40
  • 2
    ah, I didn't noticed you had tried to use `->binary`. Yes, I'm not surprised the server ignores commands when you're not logged in :) Feel free to self-answer – ikegami Jul 14 '20 at 07:43

1 Answers1

1

Put ->binary after the login.

CJ7
  • 22,579
  • 65
  • 193
  • 321