通过 ftp 将 gif 发送到不同文件夹中的服务器

Sending gif by ftp to a server in different folders

我使用 perl 将 gif 发送到服务器。我想将一些 gif 移动到名为 precipitation 的文件夹中,将其他 gif 移动到名为 wind 的文件夹中。现在用下面的代码(好吧,它是我使用的代码的一部分)我发送它们,但是代码中有问题,因为我在同一个文件夹中找到所有 gif,在第一个中,沉淀。任何的想法?

use BSD::Resource;
use File::Copy;
use Net::FTP;


#ACCIONS  send gif to the folder precipitation
$ftp->cwd("html/pen/precipitation");
foreach my $file ($ftp->ls("Pl*.gif")){
$ftp->delete($file) or die "Error in delete\n";
}
my @arxius = glob("/home/gif/Pen/Pl*.gif");
foreach my $File(@arxius){
$ftp->binary();
$ftp->put("$File");
}

#ACCIONS  send gif to the folder wind
$ftp->cwd("html/pen/wind");
foreach my $file2 ($ftp->ls("vent*.gif")){
$ftp->delete($file2) or die "Error in delete\n";
}
my @arxius2 = glob("/home/gif/Pen/vent*.gif");
foreach my $File(@arxius2){
$ftp->binary();
$ftp->put("$File");
}

该行为表明对 cwd() 的第二次调用失败。

这很可能是因为您使用的是相对路径而不是绝对路径:第二个 cwd() 调用是相对于第一个中设置的位置的。它会尝试转到 html/pen/precipitation/html/pen/wind,但这似乎不是您想要的。

在第二个 cwd() 调用中使用绝对路径或 ../wind

此外,您应该检查 cwd() 命令是否成功,如果您没有更改到预期的目录,则停止。否则,您将在错误的位置执行潜在的破坏性操作(如删除文件)!cwd() 如果有效则 return 为真,否则为假。见 Net::FTP documentation.