Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: Lib/ftplib.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/filecmp.py ('k') | Lib/idlelib/PyShell.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """An FTP client class and some helper functions. 1 """An FTP client class and some helper functions.
2 2
3 Based on RFC 959: File Transfer Protocol (FTP), by J. Postel and J. Reynolds 3 Based on RFC 959: File Transfer Protocol (FTP), by J. Postel and J. Reynolds
4 4
5 Example: 5 Example:
6 6
7 >>> from ftplib import FTP 7 >>> from ftplib import FTP
8 >>> ftp = FTP('ftp.python.org') # connect to host, default port 8 >>> ftp = FTP('ftp.python.org') # connect to host, default port
9 >>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@ 9 >>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@
10 '230 Guest login ok, access restrictions apply.' 10 '230 Guest login ok, access restrictions apply.'
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 Optional `rest' argument can be a string that is sent as the 336 Optional `rest' argument can be a string that is sent as the
337 argument to a REST command. This is essentially a server 337 argument to a REST command. This is essentially a server
338 marker used to tell the server to skip over any data up to the 338 marker used to tell the server to skip over any data up to the
339 given marker. 339 given marker.
340 """ 340 """
341 size = None 341 size = None
342 if self.passiveserver: 342 if self.passiveserver:
343 host, port = self.makepasv() 343 host, port = self.makepasv()
344 conn = socket.create_connection((host, port), self.timeout, 344 conn = socket.create_connection((host, port), self.timeout,
345 source_address=self.source_address) 345 source_address=self.source_address)
346 try: 346 if rest is not None:
347 if rest is not None: 347 self.sendcmd("REST %s" % rest)
348 self.sendcmd("REST %s" % rest) 348 resp = self.sendcmd(cmd)
349 resp = self.sendcmd(cmd) 349 # Some servers apparently send a 200 reply to
350 # Some servers apparently send a 200 reply to 350 # a LIST or STOR command, before the 150 reply
351 # a LIST or STOR command, before the 150 reply 351 # (and way before the 226 reply). This seems to
352 # (and way before the 226 reply). This seems to 352 # be in violation of the protocol (which only allows
353 # be in violation of the protocol (which only allows 353 # 1xx or error messages for LIST), so we just discard
354 # 1xx or error messages for LIST), so we just discard 354 # this response.
355 # this response. 355 if resp[0] == '2':
356 if resp[0] == '2': 356 resp = self.getresp()
357 resp = self.getresp() 357 if resp[0] != '1':
358 if resp[0] != '1': 358 raise error_reply(resp)
359 raise error_reply(resp)
360 except:
361 conn.close()
362 raise
363 else: 359 else:
364 sock = self.makeport() 360 sock = self.makeport()
365 try: 361 if rest is not None:
366 if rest is not None: 362 self.sendcmd("REST %s" % rest)
367 self.sendcmd("REST %s" % rest) 363 resp = self.sendcmd(cmd)
368 resp = self.sendcmd(cmd) 364 # See above.
369 # See above. 365 if resp[0] == '2':
370 if resp[0] == '2': 366 resp = self.getresp()
371 resp = self.getresp() 367 if resp[0] != '1':
372 if resp[0] != '1': 368 raise error_reply(resp)
373 raise error_reply(resp) 369 conn, sockaddr = sock.accept()
374 conn, sockaddr = sock.accept() 370 if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT:
375 if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT: 371 conn.settimeout(self.timeout)
376 conn.settimeout(self.timeout) 372 sock.close()
377 finally:
378 sock.close()
379 if resp[:3] == '150': 373 if resp[:3] == '150':
380 # this is conditional in case we received a 125 374 # this is conditional in case we received a 125
381 size = parse150(resp) 375 size = parse150(resp)
382 return conn, size 376 return conn, size
383 377
384 def transfercmd(self, cmd, rest=None): 378 def transfercmd(self, cmd, rest=None):
385 """Like ntransfercmd() but returns only the socket.""" 379 """Like ntransfercmd() but returns only the socket."""
386 return self.ntransfercmd(cmd, rest)[0] 380 return self.ntransfercmd(cmd, rest)[0]
387 381
388 def login(self, user = '', passwd = '', acct = ''): 382 def login(self, user = '', passwd = '', acct = ''):
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 resp = self.voidcmd('AUTH TLS') 699 resp = self.voidcmd('AUTH TLS')
706 else: 700 else:
707 resp = self.voidcmd('AUTH SSL') 701 resp = self.voidcmd('AUTH SSL')
708 if self.context is not None: 702 if self.context is not None:
709 self.sock = self.context.wrap_socket(self.sock) 703 self.sock = self.context.wrap_socket(self.sock)
710 else: 704 else:
711 self.sock = ssl.wrap_socket(self.sock, self.keyfile, 705 self.sock = ssl.wrap_socket(self.sock, self.keyfile,
712 self.certfile, 706 self.certfile,
713 ssl_version=self.ssl_version) 707 ssl_version=self.ssl_version)
714 self.file = self.sock.makefile(mode='r', encoding=self.encoding) 708 self.file = self.sock.makefile(mode='r', encoding=self.encoding)
715 return resp
716
717 def ccc(self):
718 '''Switch back to a clear-text control connection.'''
719 if not isinstance(self.sock, ssl.SSLSocket):
720 raise ValueError("not using TLS")
721 resp = self.voidcmd('CCC')
722 self.sock = self.sock.unwrap()
723 return resp 709 return resp
724 710
725 def prot_p(self): 711 def prot_p(self):
726 '''Set up secure data connection.''' 712 '''Set up secure data connection.'''
727 # PROT defines whether or not the data channel is to be protected. 713 # PROT defines whether or not the data channel is to be protected.
728 # Though RFC-2228 defines four possible protection levels, 714 # Though RFC-2228 defines four possible protection levels,
729 # RFC-4217 only recommends two, Clear and Private. 715 # RFC-4217 only recommends two, Clear and Private.
730 # Clear (PROT C) means that no security is to be used on the 716 # Clear (PROT C) means that no security is to be used on the
731 # data-channel, Private (PROT P) means that the data-channel 717 # data-channel, Private (PROT P) means that the data-channel
732 # should be protected by TLS. 718 # should be protected by TLS.
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 elif file == '-p': 1101 elif file == '-p':
1116 ftp.set_pasv(not ftp.passiveserver) 1102 ftp.set_pasv(not ftp.passiveserver)
1117 else: 1103 else:
1118 ftp.retrbinary('RETR ' + file, \ 1104 ftp.retrbinary('RETR ' + file, \
1119 sys.stdout.write, 1024) 1105 sys.stdout.write, 1024)
1120 ftp.quit() 1106 ftp.quit()
1121 1107
1122 1108
1123 if __name__ == '__main__': 1109 if __name__ == '__main__':
1124 test() 1110 test()
OLDNEW
« no previous file with comments | « Lib/filecmp.py ('k') | Lib/idlelib/PyShell.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+