Reputation: 5187
I am trying to use Net::FTP ( http://search.cpan.org/~shay/libnet-3.10/lib/Net/FTP.pm ) to upload a file to a remote server. I have:
use Net::FTP;
my $ftp = Net::FTP->new("example.com", Debug => 1) or die "Cannot connect to example.com: $@";
$ftp->login("username",'xxxx') or die "Cannot login ", $ftp->message;
$ftp->pasv();
$ftp->binary();
$ftp->cwd("/web/example.com/public_html/cgi-bin/links/admin/IMPORT") or die "Cannot change working directory ", $ftp->message;
print "Currently in: " . $ftp->pwd(). "\n";
$ftp->put("/home/chambres/web/example.com/public_html/cgi-bin/links/admin/org.csv") or die "Cannot upload ", $ftp->message;
$ftp->quit;
However, when I run it I get:
Net::FTP>>> Net::FTP(3.05)
Net::FTP>>> Exporter(5.72)
Net::FTP>>> Net::Cmd(3.05)
Net::FTP>>> IO::Socket::SSL(2.024)
Net::FTP>>> IO::Socket::IP(0.37)
Net::FTP>>> IO::Socket(1.38)
Net::FTP>>> IO::Handle(1.35)
Net::FTP=GLOB(0x182e348)<<< 220 (vsFTPd 3.0.3)
Net::FTP=GLOB(0x182e348)>>> USER username
Net::FTP=GLOB(0x182e348)<<< 331 Please specify the password.
Net::FTP=GLOB(0x182e348)>>> PASS ....
Net::FTP=GLOB(0x182e348)<<< 230 Login successful.
Net::FTP=GLOB(0x182e348)>>> EPSV
Net::FTP=GLOB(0x182e348)<<< 229 Entering Extended Passive Mode (|||12065|)
Net::FTP=GLOB(0x182e348)>>> TYPE I
Net::FTP=GLOB(0x182e348)<<< 200 Switching to Binary mode.
Net::FTP=GLOB(0x182e348)>>> CWD /web/example.com/public_html/cgi-bin/links/admin/IMPORT
Net::FTP=GLOB(0x182e348)<<< 250 Directory successfully changed.
Net::FTP=GLOB(0x182e348)>>> PWD
Net::FTP=GLOB(0x182e348)<<< 257 "/web/example.com/public_html/cgi-bin/links/admin/IMPORT" is the current directory
Currently in: /web/example.com/public_html/cgi-bin/links/admin/IMPORT
Net::FTP=GLOB(0x182e348)>>> PORT 139,162,208,252,155,199
Net::FTP=GLOB(0x182e348)<<< 200 PORT command successful. Consider using PASV.
Net::FTP=GLOB(0x182e348)>>> FEAT
Net::FTP=GLOB(0x182e348)<<< 211-Features:
Net::FTP=GLOB(0x182e348)<<< EPRT
Net::FTP=GLOB(0x182e348)<<< EPSV
Net::FTP=GLOB(0x182e348)<<< MDTM
Net::FTP=GLOB(0x182e348)<<< PASV
Net::FTP=GLOB(0x182e348)<<< REST STREAM
Net::FTP=GLOB(0x182e348)<<< SIZE
Net::FTP=GLOB(0x182e348)<<< TVFS
Net::FTP=GLOB(0x182e348)<<< 211 End
Net::FTP=GLOB(0x182e348)>>> HELP ALLO
Net::FTP=GLOB(0x182e348)<<< 214-The following commands are recognized.
Net::FTP=GLOB(0x182e348)<<< ABOR ACCT ALLO APPE CDUP CWD DELE EPRT EPSV FEAT HELP LIST MDTM MKD
Net::FTP=GLOB(0x182e348)<<< MODE NLST NOOP OPTS PASS PASV PORT PWD QUIT REIN REST RETR RMD RNFR
Net::FTP=GLOB(0x182e348)<<< RNTO SITE SIZE SMNT STAT STOR STOU STRU SYST TYPE USER XCUP XCWD XMKD
Net::FTP=GLOB(0x182e348)<<< XPWD XRMD
Net::FTP=GLOB(0x182e348)<<< 214 Help OK.
Net::FTP=GLOB(0x182e348)>>> ALLO 37954326
Net::FTP=GLOB(0x182e348)<<< 202 ALLO command ignored.
Net::FTP=GLOB(0x182e348)>>> STOR org.csv
Net::FTP=GLOB(0x182e348)<<< 425 Failed to establish connection.
<h1>Software error:</h1>
<pre>Cannot upload Failed to establish connection.
</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.
</p>
[Fri Nov 10 10:57:33 2017] export-csv-other-sites.cgi: Cannot upload Failed to establish connection.
It seems to work up until the put()
command. Any ideas as to what is going on?
Upvotes: 1
Views: 2686
Reputation: 1
I have just got the exactly same problem. My destination directory has the file created but contains nothing (empty file). I was running from Active Perl and so I tried by turning Passive Off. There was no apparent error can be observed when trying to upload in passive mode. But now I see Windows Defender poping up a window telling me that the ActivePerl was blocked. I unblock ActivePerl and now it works.
Checking your firewall or Antivirus environment might be a way to the exit of this annoying problem.
Upvotes: 0
Reputation: 123270
Net::FTP=GLOB(0x182e348)>>> PORT 139,162,208,252,155,199
Net::FTP=GLOB(0x182e348)<<< 200 PORT command successful. Consider using PASV.
FTP uses a control connection for the command and data connections for each data transfer. With the PORT command your local system is instructing the server to connect to the given IP address (139.162.208.252) and port (39879=155*256+199). Connecting from outside to some arbitrary port on your system will not work if you are behind a firewall or some NAT or if there is a firewall configured on your system. In these cases it might work to use the passive mode where the client opens a connection to the server and not the server a connection to the client.
Net::FTP=GLOB(0x182e348)>>> STOR org.csv
Net::FTP=GLOB(0x182e348)<<< 425 Failed to establish connection.
It looks like the server could not connect to your system in order to create a connection to transfer the data. Probably a firewall or NAT involved. Try passive mode.
It looks like that you tried to use passive mode already:
$ftp->pasv();
...
Net::FTP=GLOB(0x182e348)>>> EPSV
Net::FTP=GLOB(0x182e348)<<< 229 Entering Extended Passive Mode (|||12065|)
Only you did it the wrong way. The command above just sends the PASV/EPSV command to the server but does not change which mode gets used for the next data transfer. To cite from the documentation:
If for some reason you want to have complete control over the data connection, this includes generating it and calling the response method when required, then the user can use these methods to do so.
However calling these methods only affects the use of the methods above that can return a data connection. They have no effect on methods get, put, put_unique and those that do not require data connections.
To instead enable passive mode in connection with put
, get
etc use passive
not pasv
:
$ftp->passive(1);
Upvotes: 5