Prebuilt Client Modules
Applications such as mail clients,
FTP, web browsers, telnet, and Usenet news-readers are built to use
TCP/IP and sockets. Several libraries available on CPAN give you the
client-side libraries to roll your own FTP or mail reader, for
example, without having to worry about the application protocol.
(Note that there are no libraries to write your own servers to handle
these protocols.) In this section, we will take a brief look at a
couple of interesting client modules packaged under the Net hierarchy
and available as libnet
from CPAN. These
packages were also written by Graham Barr.
Net::FTP
This module implements the client side of the File Transfer Protocol and is used like this:
use Net::FTP; $ftp = Net::FTP->new("ftp.digital.com"); die "Could not connect: $!" unless $ftp; $ftp->login('anonymous', 'me@foo.com'); # Guest User; email as passwd $ftp->cwd('/pub/plan/perl/CPAN'); # cwd:Change Working Directory $ftp->get('index'); $ftp->quit();
This module supports all the commands that you can issue from a standard FTP program.
As currently implemented, the get
call blocks
until the entire file is transmitted, so while it is very useful for
a batch application (such as mirroring an FTP site nightly), you
cannot use it to write a graphical FTP client.
Net::POP3
This library gives an interface to programmatically access a POP (Post Office Protocol) server, used, for example, on dial-up connections. The POP server stores incoming email until the mail reader comes ...
Get Advanced Perl Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.