One of the backbones of the Internet is the ability to transfer files. There are thousands of fcservers from which you can download files. For the latest graphic board drivers to the best in shareware to the entire set of UNIX sources, ftp is the answer.
The program in ftp.pl downloads the Perl FAQ in compressed format from ftp.cis.ufl.edu and displays a directory in two formats.
It operates as follows:
The Perl code for ftp.pl is as follows:
#!/usr/bin/perl -w require('ftplib.pl'); use strict; my(@dirList); ftp::debug('ON'); ftp::open('ftp.cis.ufl.edu', 'anonymous', 'medined@planet.net') or die($!); @dirList = ftp::list('pub/perl/faq'); ftp::cwd('/pub/perl/faq'); ftp::binary(); ftp::gets('FAQ.gz'); @dirList = ftp::list(); print("list of /pub/perl/faq\n"); foreach (@dirList) { print("\t$_\n"); } @dirList = ftp::dir(); print("list of /pub/perl/faq\n"); foreach (@dirList) { print("\t$_\n"); } ftp::debug(); ftp::cwd('/pub/perl/faq'); @dirList = ftp::list(); print("list of /pub/perl/faq\n"); foreach (@dirList) { print("\t$_\n"); }
This program displays:
<< 220 flood FTP server (Version wu-2.4(21) Tue Apr 9 17:01:12 EDT 1996) ready. >> user anonymous << 331 Guest login ok, send your complete e-mail address as password. >> pass ..... << 230- Welcome to the << 230- University of Florida . . . << 230 Guest login ok, access restrictions apply. >> port 207,3,100,103,4,135 << 200 PORT command successful. >> nlst pub/perl/faq << 150 Opening ASCII mode data connection for file list. << 226 Transfer complete. >> cwd /pub/perl/faq << 250 CWD command successful. >> type i << 200 Type set to I. >> port 207,3,100,103,4,136 << 200 PORT command successful. >> retr FAQ.gz << 150 Opening BINARY mode data connection for FAQ.gz (75167 bytes). << 226 Transfer complete. >> port 207,3,100,103,4,138 << 200 PORT command successful. >> nlst << 150 Opening BINARY mode data connection for file list. << 226 Transfer complete. list of /pub/perl/faq FAQ FAQ.gz >> port 207,3,100,103,4, 139 << 200 PORT command successful. >> list << 150 Opening BINARY mode data connection for /bin/ls. << 226 Transfer complete. list of /pub/perl/faq total 568 drwxrwxr-x 2 1208 31 512 Nov 7 1995 . drwxrwxr-x 10 1208 68 512 Jun 18 21:32 .. -rw-rw-r-- 1 1208 31 197446 Nov 4 1995 FAQ -rw-r--r-- 1 1208 31 75167 Nov 7 1995 FAQ.gz list of /pub/perl/faq FAQ FAQ.gz
Make sure that you can pick out the different ftp commands and responses in this output. Notice that the ftp commands and responses are only displayed when the debugging feature is turned on.