1

为什么我在上传到 FTP 服务器时总是收到损坏的图像文件?.gif图像不会损坏,只有.jpeg/jpg.png损坏。

sub png{
    my $ftp=Net::FTP->new($fhost)or die &ftpErr;
    $ftp->login($hostname, $hostpass);
    my $img=$ftp->put("$file");
    $ftp->get($img);
    $ftp->quit;
    our $image="$img";
    our $shot=$window->Photo(-format=>'png',-file=>"$image");
    $window->Label(-relief=>'ridge',-image=>$shot,-width=>50,-height=>50)->pack(-anchor=>'n');
}
sub jpeg{
    my $ftp=Net::FTP->new($fhost)or die &ftpErr;
    $ftp->login($hostname, $hostpass);
    my $img=$ftp->put("$file");
    $ftp->get($img);
    $ftp->quit;
    our $image="$img";
    our $shot=$window->Photo(-format=>'jpeg',-file=>"$image");
    $window->Label(-relief=>'ridge',-image=>$shot,-width=>50,-height=>50)->pack(-anchor=>'n');
}
4

1 回答 1

2

您正在以默认模式(即 ASCII)传输文件。此模式翻译行尾。要传输二进制文件,请使用二进制模式:

  $ftp->binary;
  $ftp->put(...);
  $ftp->get(...);
于 2014-11-21T05:37:04.350 回答