来自Perl Net :: FTP的错误原因

pax*_*blo 1 ftp error-handling perl mainframe

我正在使用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;
    }
Run Code Online (Sandbox Code Playgroud)

知道无法创建数据集,CANT.WRITE.TO.THIS因为我没有所需的权限,但是当我尝试尝试时,看到的唯一消息是:

Could not put file:
Run Code Online (Sandbox Code Playgroud)

没有迹象表明$!问题出在哪里。我看了看Net::FTPdoco,上面写着:

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.

我也找不到有关检索特定错误的任何信息(类似$ftp->getLastError()或类似的东西)。

我怎样才能向用户表明为什么传输失败?

在较早的迭代中,我求助于放置文件,然后再次获取它并在本地检查内容。我真的不想再对人施加这种笨拙的代码。

Sin*_*nür 5

网络:: FTP

$ftp = Net::FTP->new("some.host.name", Debug => 0)
    or die "Cannot connect to some.host.name: $@"
Run Code Online (Sandbox Code Playgroud)

注意$@

$ftp->cwd("/pub")
    or die "Cannot change working directory ", $ftp->message;
Run Code Online (Sandbox Code Playgroud)

注意 $ftp->message