我有一个使用Net :: FTP的perl脚本将文件传输到几个不同的服务器。我能够转移到所有关于一台服务器。当我尝试PUT文件时,失败的那个会给出错误“无法建立数据连接:连接超时”。远程文件存在,但是为0字节。我可以连接到此服务器并成功将文件从我的Windows机器放在不同的位置,因此我知道远程主机正在工作。
我脚本中的源代码片段:
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
答案 0 :(得分:2)
if (
not $ftp = Net::FTP->new( Host => $feed->{ftpserver} ),
Timeout => 360,
Passive => 1,
Debug => 1
)
应该更像:
if (
not $ftp = Net::FTP->new(
Host => $feed->{ftpserver},
Timeout => 360,
Passive => 1,
Debug => 1
)
)