Perl Net::FTP 的错误原因
我正在使用 Net::FTP 将文件传输到大型机,并且正在测试故障条件。
我的代码基本上如下:
my $ftp = Net::FTP->new ("mainframe.com", Timeout => 20);
if (! $ftp) {
logMessage ("Could not connect to host: $!");
return;
}
if (! $ftp->login ("paxdiablo", "demigodemporeroftheuniverse")) {
logMessage ("Could not log in to host: $!");
$ftp->quit ();
return;
}
if (! $ftp->put ("myfile.txt", "'CANT.WRITE.TO.THIS'")) {
logMessage ("Could not put file: $!");
$ftp->quit ();
return;
}
我知道我无法创建数据集CANT.WRITE.TO.THIS
,因为我没有所需的权限,但是,当我尝试时,我看到的唯一消息是:
Could not put file:
$!
中没有指示问题所在。我查看了 Net::FTP
doco 和它说的是:
put ( LOCAL_FILE [, REMOTE_FILE ] )
将文件放在远程服务器上。 LOCAL_FILE 可以是名称或文件句柄。如果 LOCAL_FILE 是文件句柄,则必须指定 REMOTE_FILE。如果未指定 REMOTE_FILE,则该文件将存储在当前目录中,其叶名与 LOCAL_FILE 相同。
如果未给出 REMOTE_FILE,则返回 REMOTE_FILE 或生成的远程文件名。
返回 REMOTE_FILE 或生成的远程文件名。代码>
我也找不到任何有关检索特定错误的信息(例如 $ftp->getLastError()
或类似的内容)。
我如何向用户表明传输失败的原因?
在早期的迭代中,我求助于放置文件,然后再次获取它并在本地检查内容。我真的宁愿不必再次向人们强加这样的错误代码。
I'm using Net::FTP to transfer files up to a mainframe and I'm testing failure conditions.
My code is basically along the following lines:
my $ftp = Net::FTP->new ("mainframe.com", Timeout => 20);
if (! $ftp) {
logMessage ("Could not connect to host: $!");
return;
}
if (! $ftp->login ("paxdiablo", "demigodemporeroftheuniverse")) {
logMessage ("Could not log in to host: $!");
$ftp->quit ();
return;
}
if (! $ftp->put ("myfile.txt", "'CANT.WRITE.TO.THIS'")) {
logMessage ("Could not put file: $!");
$ftp->quit ();
return;
}
I know I can't create the data set CANT.WRITE.TO.THIS
since I don't have the required permissions but, when I try, the only message I see is:
Could not put file:
There is no indication in $!
as to what the problem was. I've looked in the Net::FTP
doco and all it says is:
put ( LOCAL_FILE [, REMOTE_FILE ] )
Put a file on the remote server. LOCAL_FILE may be a name or a filehandle. If LOCAL_FILE is a filehandle then REMOTE_FILE must be specified. If REMOTE_FILE is not specified then the file will be stored in the current directory with the same leafname as LOCAL_FILE.
Returns REMOTE_FILE or the generated remote filename if REMOTE_FILE is not given.
I also cannot find anything there about retrieving the specific error (like $ftp->getLastError()
or something similar).
How can I indicate to the user why the transfer failed?
On an earlier iteration, I resorted to putting the file, then getting it again and checking contents locally. I'd really rather not have to inflict such kludgy code on people again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Net::FTP:
请注意
$@
。注意
$ftp->message
From Net::FTP:
Note
$@
.Note
$ftp->message