【发布时间】:2013-05-28 20:11:49
【问题描述】:
我有一个使用 Net::FTP 将文件传输到多个不同服务器的 perl 脚本。我能够转移到所有关于一台服务器。当我尝试 PUT 文件时,失败的那个会给出错误“无法建立数据连接:连接超时”。远程文件存在,但为 0 字节。我可以连接到该服务器并成功地将文件从我的 Windows 机器放到不同的位置,所以我知道远程主机正在工作。
我的脚本中的源代码 sn-p:
sub sendfeed_ftp {
my $feed = shift;
#send the feed file first, since it's the most import part and the images will be slow
print "Sending $feed->{feedfilename} to $feed->{ftpserver}...\n";
if (
not $ftp = Net::FTP->new( Host => $feed->{ftpserver} ),
Timeout => 360,
Passive => 1,
Debug => 1
)
{
print "Can't open $feed->{ftpserver}\t", $ftp->message;
} else {
if ( not $ftp->login( $feed->{ftpuser}, $feed->{ftppassword} ) ) {
print "Can't log $feed->{ftpuser} in\t", $ftp->message;
} else {
#$ftp->binary();
if ( not $ftp->put( $workdir . $feed->{feedfilename} ) ) {
print "Can't put $workdir$feed->{feedfilename}\t",
$ftp->message;
} else {
$ftp->quit;
print "Feed file $workdir$feed->{feedfilename} sent\n";
}
}
}
}
当我尝试从运行 perl 脚本的同一台服务器手动传输文件时,会发生以下情况:
> ftp -p <HOSTNAME>
Connected to <HOSTNAME>.
220 FTP Server Ready
Name (<HOSTNAME>:dimports): <USERNAME>
331 Password required for <USERNAME>
Password:
230-***************************************************************************
NOTICE TO USERS
This computer system is private property. It is for authorized use only.
Users (authorized or unauthorized) have no explicit or implicit
expectation of privacy.
Any or all uses of this system and all files on this system may be
intercepted, monitored, recorded, copied, audited, inspected, and
disclosed to your employer, to authorized site, government, and law
enforcement personnel, as well as authorized officials of government
agencies, both domestic and foreign.
By using this system, the user consents to such interception, monitoring,
recording, copying, auditing, inspection, and disclosure at the
discretion of such personnel or officials. Unauthorized or improper use
of this system may result in civil and criminal penalties and
administrative or disciplinary action, as appropriate. By continuing to
use this system you indicate your awareness of and consent to these terms
and conditions of use. LOG OFF IMMEDIATELY if you do not agree to the
conditions stated in this warning.
****************************************************************************
230 User <USERNAME> logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> lcd outgoing/
Local directory now: /usr/home/dimports/upload/outgoing
ftp> put diamonds.csv
local: diamonds.csv remote: diamonds.csv
229 Entering Extended Passive Mode (|||50044|)
ftp: Can't connect to `<HOSTNAME>:50044': Connection timed out
【问题讨论】:
-
始终使用
use strict; use warnings;!!!!!Useless use of a constant ("Timeout") in void context,Useless use of a constant (360) in void context,Useless use of a constant ("Passive") in void context,Useless use of a constant ("Debug") in void context