• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Perl Net FTP file only half transfers then ends?

Hi,

Im trying to FTP a zip of about 100MB, it part transfers (aprox 1 third to half, diffrent each time.) then bombs out with a script error :S I dont see any problems, anyone help?
Script and error log below



use Net::FTP;
$ftpsite = "wol.XXXXXXX.net";

$ftp = Net::FTP->new("$ftpsite", Debug => 1)
or die "Can not connect to FTP site", $ftp->message;
$ftp->login("XXXXXXX",'XXXXXXX')
or die "Cannot login", $ftp->message;

$ftp->cwd("/site_backup")
or die "Cannot change working directory to /site_backup", $ftp->message;

$ftp->put ("/home/default/sharpmail.co.uk/user/htdocs/backup_tmp/htdocs.zip")
or die "put failed", $ftp->message;
$ftp->quit;
print "Done!";




[Sun Apr 30 20:01:09 2006] [error] [client 84.69.111.168] Net::FTP>>> Net::FTP(2.75)
[Sun Apr 30 20:01:09 2006] [error] [client 84.69.111.168] Net::FTP>>>   Exporter(5.58)
[Sun Apr 30 20:01:09 2006] [error] [client 84.69.111.168] Net::FTP>>>   Net::Cmd(2.26)
[Sun Apr 30 20:01:09 2006] [error] [client 84.69.111.168] Net::FTP>>>   IO::Socket::INET(1.27)
[Sun Apr 30 20:01:09 2006] [error] [client 84.69.111.168] Net::FTP>>>     IO::Socket(1.28)
[Sun Apr 30 20:01:09 2006] [error] [client 84.69.111.168] Net::FTP>>>       IO::Handle(1.24)
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 220 LINKSTATION FTP server ready
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)>>> user ftpbackup\r
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 331 Password required for ftpbackup.
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)>>> PASS ....
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 230 User ftpbackup logged in.
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)>>> CWD /site_backup\r
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 250 CWD command successful.
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)>>> ALLO 105837300\r
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 202 No storage allocation necessary.
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)>>> PASV\r
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 227 Entering Passive Mode (84,69,111,168,4,127).
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)>>> STOR htdocs.zip\r
[Sun Apr 30 20:01:14 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 150 Opening BINARY mode data connection for htdocs.zip
[Sun Apr 30 20:06:14 2006] [error] [client 84.69.111.168] Premature end of script headers: ftp.cgi
[Sun Apr 30 20:09:16 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 226 Transfer complete.
[Sun Apr 30 20:09:16 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)>>> QUIT\r
[Sun Apr 30 20:09:16 2006] [error] [client 84.69.111.168] Net::FTP=GLOB(0x9ab498c)<<< 221 Goodbye.
0
sharpmail
Asked:
sharpmail
  • 7
  • 5
  • 2
1 Solution
 
sharpmailAuthor Commented:
just a thought, could it be the script timing out? does it do that?
0
 
Kim RyanIT ConsultantCommented:
Could well be, what is the exact script wrror your are getting? Also default timeout is 120 seconds, so maybe try
$ftp = Net::FTP->new("$ftpsite", Debug => 1, Timeout => 600)
0
 
sharpmailAuthor Commented:
is this not the connection timeout? a connection is made and file partly transfered. the exact error is simply error 500 and the log shows (as above) [Sun Apr 30 20:06:14 2006] [error] [client 84.69.111.168] Premature end of script headers: ftp.cgi
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Kim RyanIT ConsultantCommented:
Yes you are right, the timeout wont help you here. 500 is a syntax error. You could try connecting in passive mode to help get around this. But the error message seems to suggest you may already be in passive mode.

At this stage, I would try the same transfer manually with  your FTP client. It will be easy to tinker with the setting from within this environment.

0
 
sharpmailAuthor Commented:
it is in passive, they are not errors in the log, i ran in debug mode, thats why they are there. the only error as such is the :

[Sun Apr 30 20:06:14 2006] [error] [client 84.69.111.168] Premature end of script headers: ftp.cgi

but this does not happen untill the script has been running for a little while and then terminated for some reason. Could the script be getting terminated by say apache? is there a way to stop this?
0
 
TintinCommented:
So you are running this script as as CGI script?  That makes a big difference when it comes to timeouts.  How long does it normally take to transfer the file?
0
 
Kim RyanIT ConsultantCommented:
Yes, that is why I would try transferring the file purely by FTP as a test. If that works you have isolated the probelm to the web sever environment.
0
 
sharpmailAuthor Commented:
I have solved it now, NET::FTP transfers as ASCII by default and it should be binary, made the transfer binary and it works fine.

$ftp->binary();

before put command.
0
 
Kim RyanIT ConsultantCommented:
that's odd becuase I checked your error log and it reporterd binary mode. Anyway, glad it's working
----
Opening BINARY mode data connection for htdocs.zip
0
 
sharpmailAuthor Commented:
thats a good point :s but when i take "  $ftp->binary();  " out it does not work - verry strange
0
 
sharpmailAuthor Commented:
have the points anyway!
0
 
TintinCommented:
That's bizare!

I don't see how having

$ftp->binary();

would solve the symptoms you had.  Doesn't make sense (to me at least)
0
 
Kim RyanIT ConsultantCommented:
Thanks for points, but yes am also still confused. Why would a text mode transfer only fail one third of the way through. Anyway I guess as the data is binary, that was the source of the problem
0
 
sharpmailAuthor Commented:
well it seems it did not fail half way as such, its just the zip was corrupted when it reach the destination (windows) adding binary, for what ever reason means its working :s
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now