Chapter 13. FTP Webbots

File transfer protocol (FTP) is among the oldest Internet protocols.[41] It dates from the Internet’s predecessor ARPANET, which was originally funded by the Eisenhower administration.[42] Research centers started using FTP to exchange large files in the early 1970s, and FTP became the de facto transport protocol for email, a status it maintained until the early 1990s. Today, system administrators commonly use FTP to give web developers access to files on remote webservers. Though it’s an older protocol, FTP still allows computers with dissimilar technologies to share files, independent of file structure and operating system.

To better understand how an FTP-capable webbot may be useful, consider this scenario. A national retailer needs to move large sales reports from each of its stores to a centralized corporate webserver. This particular retail chain was built through acquisition, so it is built from proprietary computer systems using multiple protocols. The one thing all of these systems have in common is access to an FTP server. The goal for this project is to use the commonality of FTP to span the differences between systems to download store sales reports and move them to the corporate server.

The script for this example project is available for study at this book’s website. Just remember that the script satisfies a ficticious scenario and will not run unless you change the configuration. In this chapter, I have split it up and annotated the sections for clarity. Example 13-1 shows the initialization for the FTP servers.

This program also configures a routine to send a short email notification when commands fail. (Email functions for webbots, and LIB_mail, are described in Chapter 14 and Chapter 15.) Automated email error notification allows the script to run autonomously without requiring that someone verify the operation manually.[43] Example 13-2 shows the email configuration script.

The next step is to make a connection to the remote FTP server. After making the connection, the script authenticates itself with a username and password, as shown in Example 13-3.

Once authenticated by the server, the script moves to the target file’s directory and downloads the file to the local filesystem. After downloading the file, the script closes the connection to the remote server, as shown in Example 13-4.

The final task, shown in Example 13-5, uploads the file to the corporate server using techniques similar to the ones used to download the file.



[41] The original document defining FTP can be viewed at http://www.w3.org/Protocols/rfc959.

[42] Katie Hafner and Matthew Lyon, Where Wizards Stay Up Late: The Origins of the Internet (New York: Simon & Schuster, 1996), 14.

[43] See Chapter 22 for information on how to make webbots run periodically.