[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

More Than One Way to Push Bits over the Net


Finally, let’s discuss some context. We’ve seen three getfile scripts at this point in the
book. The one in this chapter is different from the other two we wrote in earlier chap-
ters, but it accomplishes a similar goal:



  • This chapter’s getfile is a server-side CGI script that displays files over the HTTP
    protocol (on port 80).

  • In Chapter 12, we built a client- and server-side getfile to transfer with raw sockets
    (on port 50001).

  • In Chapter 13, we implemented a client-side getfile to ship over FTP (on port 21).


Really, the getfile CGI script in this chapter simply displays files only, but it can be
considered a download tool when augmented with cut-and-paste operations in a web
browser. Moreover, the CGI- and HTTP-based putfile script here is also different from
the FTP-based putfile in Chapter 13, but it can be considered an alternative to both
socket and FTP uploads.


The point to notice is that there are a variety of ways to ship files around the Internet—
sockets, FTP, and HTTP (web pages) can move files between computers. Technically
speaking, we can transfer files with other techniques and protocols, too—Post Office
Protocol (POP) email, Network News Transfer Protocol (NNTP) news, Telnet, and
so on.


Each technique has unique properties but does similar work in the end: moving bits
over the Net. All ultimately run over sockets on a particular port, but protocols like
FTP and HTTP add additional structure to the socket layer, and application models
like CGI add both structure and programmability.


In the next chapter, we’re going to use what we’ve learned here to build a more sub-
stantial application that runs entirely on the Web—PyMailCGI, a web-based email
tool, which allows us to send and view emails in a browser, process email attachments,
and more. At the end of the day, though, it’s mostly just bytes over sockets, with a user
interface.


Transferring Files to Clients and Servers | 1227
Free download pdf