[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
...lines omitted... downloading ora-pyref4e.gif to test\ora-pyref4e.gif as image downloading ora-lp4e-big.jpg to test\ora-lp4e-b ...
the downloaded files (it defaults to “.”, the directory where the script is run). Command-line arguments could be employed to un ...
nonpassive = False # passive FTP by default remotesite = 'learning-python.com' # upload to this site remotedir = 'books' # from ...
Similar to the mirror download script, this program illustrates a handful of new FTP interfaces and a set of FTP scripting techn ...
This ftplib string processing worked with text-mode files in Python 2.X, but only because there was no separate bytes type; \n w ...
uploading test\zaurus0.jpg to zaurus0.jpg as image uploading test\zaurus1.jpg to zaurus1.jpg as image uploading test\zaurus2.jpg ...
To demonstrate how we might do better, Example 13-12 shows one way to refactor (reorganize) the download script. By wrapping its ...
return maintype == 'text' and encoding == None # not compressed def connectFtp(cf): print('connecting...') connection = ftplib.F ...
changed its behavior, though, we’ve modified the script’s software structure radically— its code is now a set of tools that can ...
conn = connectFtp(cf) cleanRemotes(cf, conn) uploadAll(cf, conn) Not only is the upload script simpler now because it reuses com ...
invoke both an upload and download; for the uploadall variant and possibly others, also make single file upload/download code in ...
return maintype == 'text' and encoding == None # not compressed def connectFtp(self): print('connecting...') connection = ftplib ...
localfile = open(localpath, 'rb') self.connection.storlines('STOR ' + remotename, localfile) else: localfile = open(localpath, ' ...
else: print('Usage: ftptools.py ["download" | "upload"] [localdir]') In fact, this last mutation combines uploads and downloads ...
For my purposes, that’s often a reasonable constraint. I avoid nested subdirectories to keep things simple, and I store my book ...
for each directory in an entire tree upload simple files, recur into subdirectories """ localfiles = os.listdir(localdir) for lo ...
much of the same code by inheritance), but notice that it traverses and uploads nested subdirectories along the way: C:\...\PP4E ...
To get rid of all the files accidentally uploaded, I quickly wrote the script in Exam- ple 13-16 in emergency (really, panic) mo ...
self.connection.cwd(fname) # chdir into remote dir self.cleanDir() # clean subdirectory self.connection.cwd('..') # chdir remote ...
>>> f.dir(L.append) # ditto for detailed list >>> for x in L[:3]: print(x) ... -rw-r--r-- 1 ftp ftp 8173 Mar 1 ...
«
42
43
44
45
46
47
48
49
50
51
»
Free download pdf