Hello to all you Perl-lovers,

Can anyone tell me how to download a file using IO::Socket from a
FTP-server??  What do I have to change in the
following code (which is used for HTTP-connections) to make it work with a
FTP-server ???

TIA !

Jorn

#############################################################################

$port = 80;

   $remote = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>$server, PeerPort=>"80", 
Reuse=>1)

   or die "Can't connect to \"$server\"\n";

   # set buffering off
   $remote->autoflush(1);

   # the request text
   $tosend = "GET $document HTTP/1.0\n";
   $tosend .= "Host: $server\n\n";
   $ltosend = length($tosend);

   # try to write
   $nwritten = syswrite($remote, $tosend, $ltosend);

   # if not everthing was send die
   if ($nwritten < $ltosend)
   { die "error: couldn't send all data to server. aborting\n"
   }

   # receive everything the server sends, and print it to a file

   open(FILE, ">$filename");
   binmode(FILE);

   # First chunk of data consists of HTTP-headers --> lose them !

   $nread = sysread($remote, $inp, 1024);
   $inp =~s/^(.*?)\r\n\r\n//sm;
   print FILE $inp;

   do {
         # try to read
         $nread = sysread($remote, $inp, 1024);

         # print written stuff
         print FILE $inp;

         # end reading if nothing was read

   } while ($nread > 0);
   close $remote;
   close(FILE)

   print "Content-type: text/html\n\n";
   print "All done";


#############################################################################


---------------------------------------------------------------------------
This message (including any attachments) is confidential and may be privileged. If you 
have received it by mistake please notify the sender by return
e-mail and delete this message from your system. Any unauthorised use or dissemination 
of this message in whole or in part is strictly prohibited.
Please note that e-mails are susceptible to change.
ABN AMRO Bank N.V. (including its group companies) shall not be liable for the 
improper or incomplete transmission of the information contained in
this communication nor for any delay in its receipt or damage to your system. ABN AMRO 
Bank N.V. (or its group companies) does not guarantee that the
integrity of this communication has been maintained nor that this communication is 
free of viruses, interceptions or interference.
---------------------------------------------------------------------------



_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to