Reputation: 1599
I've got a perl script using Net::FTP to transfer a file to several different servers. I am able to transfer to all about one server. The one that's failing gives the error "Unable to build data connection: Connection timed out" when I try to PUT a file. The remote file exists, but is 0 bytes. I can connect to this server and successfully put the file from my Windows machine in a different location, so I know the remote host is working.
Source code snippet from my script:
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";
}
}
}
}
Here's what happens when I try to transfer the file manually from the same server running the perl script:
> 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
Upvotes: 2
Views: 1551
Reputation: 50637
if (
not $ftp = Net::FTP->new( Host => $feed->{ftpserver} ),
Timeout => 360,
Passive => 1,
Debug => 1
)
should be more like:
if (
not $ftp = Net::FTP->new(
Host => $feed->{ftpserver},
Timeout => 360,
Passive => 1,
Debug => 1
)
)
Upvotes: 2