/snap/core20/2769/usr/lib/python3.8/__pycache__
NameSizeModeActions
abc.cpython-38.pyc53340644editdlrm
aifc.cpython-38.pyc254740644editdlrm
antigravity.cpython-38.pyc7970644editdlrm
argparse.cpython-38.pyc625910644editdlrm
ast.cpython-38.pyc167630644editdlrm
asynchat.cpython-38.pyc68510644editdlrm
asyncore.cpython-38.pyc160280644editdlrm
base64.cpython-38.pyc170710644editdlrm
bdb.cpython-38.pyc249210644editdlrm
binhex.cpython-38.pyc121340644editdlrm
bisect.cpython-38.pyc23540644editdlrm
bz2.cpython-38.pyc114450644editdlrm
calendar.cpython-38.pyc270640644editdlrm
cgi.cpython-38.pyc265440644editdlrm
cgitb.cpython-38.pyc101500644editdlrm
chunk.cpython-38.pyc48390644editdlrm
cmd.cpython-38.pyc126260644editdlrm
code.cpython-38.pyc99130644editdlrm
codecs.cpython-38.pyc339560644editdlrm
codeop.cpython-38.pyc64170644editdlrm
colorsys.cpython-38.pyc32400644editdlrm
compileall.cpython-38.pyc94100644editdlrm
configparser.cpython-38.pyc457180644editdlrm
contextlib.cpython-38.pyc202290644editdlrm
contextvars.cpython-38.pyc2430644editdlrm
copy.cpython-38.pyc69870644editdlrm
copyreg.cpython-38.pyc43180644editdlrm
cProfile.cpython-38.pyc54800644editdlrm
crypt.cpython-38.pyc33870644editdlrm
csv.cpython-38.pyc119100644editdlrm
dataclasses.cpython-38.pyc236530644editdlrm
datetime.cpython-38.pyc571730644editdlrm
decimal.cpython-38.pyc3590644editdlrm
difflib.cpython-38.pyc594380644editdlrm
dis.cpython-38.pyc158080644editdlrm
doctest.cpython-38.pyc759740644editdlrm
dummy_threading.cpython-38.pyc11100644editdlrm
enum.cpython-38.pyc259620644editdlrm
filecmp.cpython-38.pyc84270644editdlrm
fileinput.cpython-38.pyc133730644editdlrm
fnmatch.cpython-38.pyc33550644editdlrm
formatter.cpython-38.pyc175450644editdlrm
fractions.cpython-38.pyc187390644editdlrm
ftplib.cpython-38.pyc280070644editdlrm
functools.cpython-38.pyc279010644editdlrm
genericpath.cpython-38.pyc40010644editdlrm
getopt.cpython-38.pyc62710644editdlrm
getpass.cpython-38.pyc41780644editdlrm
gettext.cpython-38.pyc180000644editdlrm
glob.cpython-38.pyc43430644editdlrm
gzip.cpython-38.pyc181840644editdlrm
hashlib.cpython-38.pyc67270644editdlrm
heapq.cpython-38.pyc140700644editdlrm
hmac.cpython-38.pyc63880644editdlrm
imaplib.cpython-38.pyc414640644editdlrm
imghdr.cpython-38.pyc41180644editdlrm
imp.cpython-38.pyc98090644editdlrm
inspect.cpython-38.pyc805930644editdlrm
io.cpython-38.pyc34540644editdlrm
ipaddress.cpython-38.pyc628290644editdlrm
keyword.cpython-38.pyc9980644editdlrm
linecache.cpython-38.pyc38670644editdlrm
locale.cpython-38.pyc346740644editdlrm
lzma.cpython-38.pyc120180644editdlrm
mailbox.cpython-38.pyc602640644editdlrm
mailcap.cpython-38.pyc72060644editdlrm
mimetypes.cpython-38.pyc160310644editdlrm
modulefinder.cpython-38.pyc161150644editdlrm
netrc.cpython-38.pyc37770644editdlrm
nntplib.cpython-38.pyc339740644editdlrm
ntpath.cpython-38.pyc140910644editdlrm
nturl2path.cpython-38.pyc17440644editdlrm
numbers.cpython-38.pyc122020644editdlrm
opcode.cpython-38.pyc54200644editdlrm
operator.cpython-38.pyc136910644editdlrm
optparse.cpython-38.pyc480570644editdlrm
os.cpython-38.pyc313970644editdlrm
pathlib.cpython-38.pyc442090644editdlrm
pdb.cpython-38.pyc472260644editdlrm
pickle.cpython-38.pyc469080644editdlrm
pickletools.cpython-38.pyc672040644editdlrm
pipes.cpython-38.pyc77950644editdlrm
pkgutil.cpython-38.pyc163090644editdlrm
platform.cpython-38.pyc243260644editdlrm
plistlib.cpython-38.pyc273740644editdlrm
poplib.cpython-38.pyc135560644editdlrm
posixpath.cpython-38.pyc104610644editdlrm
pprint.cpython-38.pyc162810644editdlrm
profile.cpython-38.pyc147580644editdlrm
pstats.cpython-38.pyc220660644editdlrm
pty.cpython-38.pyc39550644editdlrm
pyclbr.cpython-38.pyc104510644editdlrm
pydoc.cpython-38.pyc836460644editdlrm
py_compile.cpython-38.pyc73520644editdlrm
queue.cpython-38.pyc106260644editdlrm
quopri.cpython-38.pyc57480644editdlrm
random.cpython-38.pyc201080644editdlrm
re.cpython-38.pyc144220644editdlrm
reprlib.cpython-38.pyc53030644editdlrm
rlcompleter.cpython-38.pyc57550644editdlrm
runpy.cpython-38.pyc81810644editdlrm
sched.cpython-38.pyc65320644editdlrm
secrets.cpython-38.pyc21900644editdlrm
selectors.cpython-38.pyc169350644editdlrm
shelve.cpython-38.pyc94900644editdlrm
shlex.cpython-38.pyc75360644editdlrm
shutil.cpython-38.pyc372190644editdlrm
signal.cpython-38.pyc28430644editdlrm
site.cpython-38.pyc171680644editdlrm
sitecustomize.cpython-38.pyc2200644editdlrm
smtpd.cpython-38.pyc264630644editdlrm
smtplib.cpython-38.pyc355320644editdlrm
sndhdr.cpython-38.pyc69890644editdlrm
socket.cpython-38.pyc277870644editdlrm
socketserver.cpython-38.pyc253610644editdlrm
sre_compile.cpython-38.pyc151420644editdlrm
sre_constants.cpython-38.pyc63590644editdlrm
sre_parse.cpython-38.pyc216470644editdlrm
ssl.cpython-38.pyc450370644editdlrm
stat.cpython-38.pyc43720644editdlrm
statistics.cpython-38.pyc336530644editdlrm
string.cpython-38.pyc73000644editdlrm
stringprep.cpython-38.pyc110170644editdlrm
struct.cpython-38.pyc3300644editdlrm
subprocess.cpython-38.pyc419670644editdlrm
sunau.cpython-38.pyc170800644editdlrm
symbol.cpython-38.pyc24040644editdlrm
symtable.cpython-38.pyc113220644editdlrm
sysconfig.cpython-38.pyc158370644editdlrm
tabnanny.cpython-38.pyc70300644editdlrm
tarfile.cpython-38.pyc630430644editdlrm
telnetlib.cpython-38.pyc182370644editdlrm
tempfile.cpython-38.pyc266530644editdlrm
textwrap.cpython-38.pyc135190644editdlrm
this.cpython-38.pyc12610644editdlrm
threading.cpython-38.pyc399760644editdlrm
timeit.cpython-38.pyc117770644editdlrm
token.cpython-38.pyc24850644editdlrm
tokenize.cpython-38.pyc171600644editdlrm
trace.cpython-38.pyc200260644editdlrm
traceback.cpython-38.pyc199380644editdlrm
tracemalloc.cpython-38.pyc173630644editdlrm
tty.cpython-38.pyc10760644editdlrm
turtle.cpython-38.pyc1300220644editdlrm
types.cpython-38.pyc91770644editdlrm
typing.cpython-38.pyc624200644editdlrm
uu.cpython-38.pyc36050644editdlrm
uuid.cpython-38.pyc236830644editdlrm
warnings.cpython-38.pyc136520644editdlrm
wave.cpython-38.pyc181490644editdlrm
weakref.cpython-38.pyc195180644editdlrm
webbrowser.cpython-38.pyc171200644editdlrm
xdrlib.cpython-38.pyc82210644editdlrm
zipapp.cpython-38.pyc58540644editdlrm
zipfile.cpython-38.pyc593360644editdlrm
zipimport.cpython-38.pyc172750644editdlrm
_bootlocale.cpython-38.pyc12430644editdlrm
_collections_abc.cpython-38.pyc287410644editdlrm
_compat_pickle.cpython-38.pyc55010644editdlrm
_compression.cpython-38.pyc41460644editdlrm
_dummy_thread.cpython-38.pyc60370644editdlrm
_markupbase.cpython-38.pyc77900644editdlrm
_osx_support.cpython-38.pyc115930644editdlrm
_pydecimal.cpython-38.pyc1607350644editdlrm
_pyio.cpython-38.pyc740790644editdlrm
_py_abc.cpython-38.pyc46700644editdlrm
_sitebuiltins.cpython-38.pyc34810644editdlrm
_strptime.cpython-38.pyc160440644editdlrm
_sysconfigdata__linux_x86_64-linux-gnu.cpython-38.pyc211210644editdlrm
_sysconfigdata__x86_64-linux-gnu.cpython-38.pyc211150644editdlrm
_threading_local.cpython-38.pyc64460644editdlrm
_weakrefset.cpython-38.pyc76000644editdlrm
__future__.cpython-38.pyc41580644editdlrm
__phello__.foo.cpython-38.pyc1270644editdlrm
Edit: /snap/core20/2769/usr/lib/python3.8/__pycache__/ftplib.cpython-38.pyc (28007B)
U yi9@sVdZddlZddlZddlmZdddddd gZd Zd Zd ZGd ddeZ Gddde Z Gddde Z Gddde Z Gddde Z e eefZdZdZGdddZz ddlZWnek rdZYn0XejZGdddeZede eeejfZdaddZdaddZddZddZ d d!Z!d)d$d%Z"d&d'Z#e$d(krRe#dS)*aSAn FTP client class and some helper functions. Based on RFC 959: File Transfer Protocol (FTP), by J. Postel and J. Reynolds Example: >>> from ftplib import FTP >>> ftp = FTP('ftp.python.org') # connect to host, default port >>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@ '230 Guest login ok, access restrictions apply.' >>> ftp.retrlines('LIST') # list directory contents total 9 drwxr-xr-x 8 root wheel 1024 Jan 3 1994 . drwxr-xr-x 8 root wheel 1024 Jan 3 1994 .. drwxr-xr-x 2 root wheel 1024 Jan 3 1994 bin drwxr-xr-x 2 root wheel 1024 Jan 3 1994 etc d-wxrwxr-x 2 ftp wheel 1024 Sep 5 13:43 incoming drwxr-xr-x 2 root wheel 1024 Nov 17 1993 lib drwxr-xr-x 6 1094 wheel 1024 Sep 13 19:07 pub drwxr-xr-x 3 root wheel 1024 Jan 3 1994 usr -rw-r--r-- 1 root root 312 Aug 1 1994 welcome.msg '226 Transfer complete.' >>> ftp.quit() '221 Goodbye.' >>> A nice test that reveals some of the network dialogue would be: python ftplib.py -d localhost -l -p -l N)_GLOBAL_DEFAULT_TIMEOUTFTP error_reply error_temp error_perm error_proto all_errors c@s eZdZdS)ErrorN__name__ __module__ __qualname__rr/usr/lib/python3.8/ftplib.pyr 9sr c@s eZdZdS)rNr rrrrr:sc@s eZdZdS)rNr rrrrr;sc@s eZdZdS)rNr rrrrr<sc@s eZdZdS)rNr rrrrr=s s c@seZdZdZdZdZeZeZ dZ dZ dZ dZ dZdZddddedfdd Zd d Zd d Zd\ddZddZddZeZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Z d'd(Z!d)d*Z"d+d,Z#d-d.Z$d/d0Z%d1d2Z&d]d3d4Z'd^d5d6Z(d_d7d8Z)d`d:d;Z*dadd?Z,dcd@dAZ-dBdCZ.dDdEZ/dFdGZ0dgfdHdIZ1dJdKZ2dLdMZ3dNdOZ4dPdQZ5dRdSZ6dTdUZ7dVdWZ8dXdYZ9dZd[Z:dS)drayAn FTP client class. To create a connection, call the class using these arguments: host, user, passwd, acct, timeout The first four arguments are all strings, and have default value ''. timeout must be numeric and defaults to None if not passed, meaning that no timeout will be set on any ftp socket(s) If a timeout is passed, then this is now the default timeout for all ftp socket operations for this instance. Then use self.connect() with optional host and port argument. To download a file, use ftp.retrlines('RETR ' + filename), or ftp.retrbinary() with slightly different arguments. To upload a file, use ftp.storlines() or ftp.storbinary(), which have an open file as argument (see their definitions below for details). The download/upload functions first issue appropriate TYPE and PORT or PASV commands. rNr zlatin-1FcCs0||_||_|r,|||r,||||dSN)source_addresstimeoutconnectlogin)selfhostuserpasswdacctrrrrr__init__rs  z FTP.__init__cCs|Srrrrrr __enter__{sz FTP.__enter__c GsN|jdk rJz*z |Wnttfk r0YnXW5|jdk rH|XdSr)sockclosequitOSErrorEOFError)rargsrrr__exit__s    z FTP.__exit__cCs|dkr||_|dkr||_|dkr*||_|dk r8||_td||j|jtj|j|jf|j|jd|_|jj |_ |jj d|j d|_ ||_|jS) awConnect to host. Arguments are: - host: hostname to connect to (string, default previous host) - port: port to connect to (integer, default previous port) - timeout: the timeout to set against the ftp socket(s) - source_address: a 2-tuple (host, port) for the socket to bind to as its source address before connecting. rrr)Nzftplib.connectrrencoding)rportrrsysauditsocketcreate_connectionr"familyafmakefiler-filegetrespwelcome)rrr.rrrrrrs   z FTP.connectcCs|jrtd||j|jS)z`Get the welcome message from the server. (this is read and squirreled away by connect())z *welcome*) debuggingprintsanitizer8r rrr getwelcomeszFTP.getwelcomecCs ||_dS)zSet the debugging level. The required argument level means: 0: no debugging output (default) 1: print commands and responses but not body text etc. 2: also print raw lines read and sent before stripping CR/LFN)r9)rlevelrrrset_debuglevelszFTP.set_debuglevelcCs ||_dS)zUse passive or active mode for data transfers. With a false argument, use the normal PORT mode, With a true argument, use the PASV command.N) passiveserver)rvalrrrset_pasvsz FTP.set_pasvcCsJ|dddkrBt|d}|ddd|d||d}t|S)N>pass PASS r*)lenrstriprepr)rsirrrr;s$z FTP.sanitizecCs`d|ksd|krtdtd|||t}|jdkrHtd|||j| |j dS)N  z4an illegal newline character should not be containedzftplib.sendcmdr z*put*) ValueErrorr/r0CRLFr9r:r;r"sendallencoder-rlinerrrputlines z FTP.putlinecCs$|jrtd||||dS)Nz*cmd*)r9r:r;rSrQrrrputcmdsz FTP.putcmdcCs|j|jd}t||jkr.td|j|jdkrHtd|||sPt|ddt krn|dd}n|ddt kr|dd}|S)Nr got more than %d bytesz*get*) r6readlinemaxlinerFr r9r:r;r&rNrQrrrgetlines  z FTP.getlinecCs`|}|dddkr\|dd}|}|d|}|dd|kr$|dddkr$q\q$|S)N-rL)rZ)rrRcodeZnextlinerrr getmultilines  zFTP.getmultilinecCsp|}|jrtd|||dd|_|dd}|dkrD|S|dkrTt||dkrdt|t|dS)Nz*resp*r[r >32145)r_r9r:r;Zlastresprrr)rrespcrrrr7s z FTP.getrespcCs$|}|dddkr t||S)z%Expect a response beginning with '2'.Nr ra)r7rrrerrrvoidrespsz FTP.voidrespcCsTdt}|jdkr"td|||j|t|}|dddkrPt||S)zAbort a file transfer. Uses out-of-band data. This does not follow the procedure from the RFC to send Telnet IP and Synch; that doesn't seem to work with the servers I've tried. Instead, just send the ABOR command as OOB data.ABORr z *put urgent*Nr[225426226) B_CRLFr9r:r;r"rOMSG_OOBr_rrrRrerrraborts z FTP.abortcCs|||S)z'Send a command and return the response.)rTr7rcmdrrrsendcmds z FTP.sendcmdcCs|||S)z8Send a command and expect a response beginning with '2'.)rTrhrrrrrvoidcmds z FTP.voidcmdcCsB|d}t|dt|dg}||}dd|}||S)zUSend a PORT command with the current host and the given port number. .zPORT ,)splitrHjoinru)rrr.ZhbytesZpbytesbytesrsrrrsendports  z FTP.sendportcCsbd}|jtjkrd}|jtjkr$d}|dkr4tddt||t|dg}dd|}||S)zESend an EPRT command with the current host and the given port number.rr zunsupported address familyrzEPRT |)r4r1AF_INETZAF_INET6rrHrzru)rrr.r4Zfieldsrsrrrsendeprt&s  z FTP.sendeprtcCsltjd|jdd}|d}|jd}|jtjkrF|||}n |||}|jt k rh| |j|S)z3Create a new socket and send a PORT command for it.)rrr )r3Zbacklogr) r1Z create_serverr4Z getsocknamer"rr|rrr settimeout)rr"r.rrerrrmakeport3s     z FTP.makeportcCs\|jtjkr:t|d\}}|jr*|}qT|jd}nt|d|j\}}||fS)z (address, port)PASVrZEPSV) r4r1rparse227rttrust_server_pasv_ipv4_addressr"Z getpeernameparse229)rZuntrusted_hostr.rrrrmakepasv@s z FTP.makepasvc Cs6d}|jr|\}}tj||f|j|jd}zL|dk rF|d|||}|ddkrd|}|ddkrxt|Wn| YnXn| r}|dk r|d|||}|ddkr|}|ddkrt|| \}} |jt k r | |jW5QRX|dddkr.t|}||fS) aInitiate a transfer over the data connection. If the transfer is active, send a port command and the transfer command, and accept the connection. If the server is passive, send a pasv command, connect to it, and start the transfer command. Either way, return the socket for the connection and the expected size of the transfer. The expected size may be None if it could not be determined. Optional `rest' argument can be a string that is sent as the argument to a REST command. This is essentially a server marker used to tell the server to skip over any data up to the given marker. Nr*zREST %srrarbr[150)r?rr1r2rrrtr7rr#rZacceptrrparse150) rrsrestsizerr.connrer"Zsockaddrrrr ntransfercmdLs>            zFTP.ntransfercmdcCs|||dS)z0Like ntransfercmd() but returns only the socket.r)r)rrsrrrr transfercmdszFTP.transfercmdcCs|sd}|sd}|sd}|dkr0|dkr0|d}|d|}|ddkrX|d|}|ddkrr|d |}|dd krt||S) zLogin, default anonymous.Z anonymousr>rr]z anonymous@zUSER rr`rDACCT rartr)rrrrrerrrrs    z FTP.loginr c Cs^|d|||:}||}|s(q2||qtdk rLt|trL|W5QRX|S)aRetrieve data in binary mode. A new port is created for you. Args: cmd: A RETR command. callback: A single parameter callable to be called on each block of data read. blocksize: The maximum number of bytes to read from the socket at one time. [default: 8192] rest: Passed to transfercmd(). [default: None] Returns: The response code. TYPE IN)rurZrecv _SSLSocket isinstanceunwraprh)rrscallback blocksizerrdatarrr retrbinarys   zFTP.retrbinaryc Cs|dkr t}|d}||}|jd|jd}||jd}t||jkr`td|j|j dkrxt dt ||s~q|d dt kr|dd }n|d dd kr|dd }||q4t dk rt|t r|W5QRXW5QRX|S) ahRetrieve data in line mode. A new port is created for you. Args: cmd: A RETR, LIST, or NLST command. callback: An optional single parameter callable that is called for each line with the trailing CRLF stripped. [default: print_line()] Returns: The response code. NTYPE Ar+r,r rUr}z*retr*rVrWrL) print_linertrr5r-rXrYrFr r9r:rHrNrrrrh)rrsrrerfprRrrr retrliness,      z FTP.retrlinesc Csl|d|||H}||}|s(q@|||r||qtdk rZt|trZ|W5QRX|S)a9Store a file in binary mode. A new port is created for you. Args: cmd: A STOR command. fp: A file-like object with a read(num_bytes) method. blocksize: The maximum data size to read from fp and send over the connection at once. [default: 8192] callback: An optional single parameter callable that is called on each block of data after it is sent. [default: None] rest: Passed to transfercmd(). [default: None] Returns: The response code. rN)rurreadrOrrrrh)rrsrrrrrbufrrr storbinarys    zFTP.storbinaryc Cs|d||}||jd}t||jkrBtd|j|sHq|ddtkrx|dtkrp|dd}|t}|||r||qtdk rt |tr| W5QRX| S)ahStore a file in line mode. A new port is created for you. Args: cmd: A STOR command. fp: A file-like object with a readline() method. callback: An optional single parameter callable that is called on each line after it is sent. [default: None] Returns: The response code. rr rUrVNrW) rurrXrYrFr rnrOrrrrh)rrsrrrrrrr storliness"     z FTP.storlinescCsd|}||S)zSend new account name.rru)rZpasswordrsrrrrszFTP.acctcGs0d}|D]}|d|}qg}|||j|S)zBReturn a list of files in a given directory (default the current).ZNLST )rappend)rr'rsargfilesrrrnlsts zFTP.nlstcGshd}d}|ddr>t|dtdkr>|dd|d}}|D]}|rB|d|}qB|||dS)aList a directory in long form. By default list current directory to stdout. Optional last argument is callback function; all non-empty arguments before it are concatenated to the LIST command. (This *should* only be used for a pathname.)ZLISTNrWrr)typer)rr'rsfuncrrrrdir(s zFTP.dirc cs|r|dd|d|r*d|}nd}g}|||j|D]\}|td\}}}i} |dddD] } | d\} }} | | | <qt|| fVqDdS) a<List a directory in a standardized format by using MLSD command (RFC-3659). If path is omitted the current directory is assumed. "facts" is a list of strings representing the type of information desired (e.g. ["type", "size", "perm"]). Return a generator object yielding a tuple of two elements for every file found in path. First element is the file name, the second one is a dictionary including a variable number of "facts" depending on the server and whether "facts" argument has been provided. z OPTS MLST ;zMLSD %sZMLSDrNrW=) rtrzrrrGrN partitionrylower) rpathZfactsrslinesrRZ facts_found_nameentryZfactkeyvaluerrrmlsd7s  zFTP.mlsdcCs0|d|}|ddkr"t||d|S)zRename a file.zRNFR rr`zRNTO )rtrru)rZfromnameZtonamererrrrenameSs z FTP.renamecCs.|d|}|dddkr"|St|dS)zDelete a file.zDELE Nr[>200250r)rfilenamererrrdeleteZsz FTP.deletec Csp|dkrRz |dWStk rN}z|jddddkr>W5d}~XYq^Xn |dkr^d}d |}||S) zChange to a directory.z..ZCDUPrNr[500rrvzCWD )rurr')rdirnamemsgrsrrrcwdbs zFTP.cwdcCs:|d|}|dddkr6|dd}t|SdS)zRetrieve the size of a file.zSIZE Nr[Z213)rtstripint)rrrerIrrrroszFTP.sizecCs$|d|}|dsdSt|S)z+Make a directory, return its full pathname.zMKD 257rru startswithparse257)rrrerrrmkdws zFTP.mkdcCs|d|S)zRemove a directory.zRMD r)rrrrrrmdszFTP.rmdcCs |d}|dsdSt|S)z!Return current working directory.ZPWDrrrrgrrrpwds  zFTP.pwdcCs|d}||S)zQuit, and close the connection.ZQUIT)rur#rgrrrr$s zFTP.quitcCsDz |j}d|_|dk r|W5|j}d|_|dk r>|XdS)z8Close the connection without assuming anything about it.N)r"r#r6)rr"r6rrrr#s z FTP.close)rrr)N)N)N)rrr)r N)N)r NN)N);rrr__doc__r9rFTP_PORTr.MAXLINErYr"r6r8r?r-rrrr!r(rr<r>debugrAr;rSrTrZr_r7rhrqrtrur|rrrrrrrrrrrrrrrrrrrrrr$r#rrrrrJsp       7    #      c @sneZdZdZejZdddddddedf ddZdddZ d d Z d d Z d dZ ddZ dddZddZdS)FTP_TLSaA FTP subclass which adds TLS support to FTP as described in RFC-4217. Connect as usual to port 21 implicitly securing the FTP control connection before authenticating. Securing the data connection requires user to explicitly ask for it by calling prot_p() method. Usage example: >>> from ftplib import FTP_TLS >>> ftps = FTP_TLS('ftp.python.org') >>> ftps.login() # login anonymously previously securing control channel '230 Guest login ok, access restrictions apply.' >>> ftps.prot_p() # switch to secure data connection '200 Protection level set to P' >>> ftps.retrlines('LIST') # list directory content securely total 9 drwxr-xr-x 8 root wheel 1024 Jan 3 1994 . drwxr-xr-x 8 root wheel 1024 Jan 3 1994 .. drwxr-xr-x 2 root wheel 1024 Jan 3 1994 bin drwxr-xr-x 2 root wheel 1024 Jan 3 1994 etc d-wxrwxr-x 2 ftp wheel 1024 Sep 5 13:43 incoming drwxr-xr-x 2 root wheel 1024 Nov 17 1993 lib drwxr-xr-x 6 1094 wheel 1024 Sep 13 19:07 pub drwxr-xr-x 3 root wheel 1024 Jan 3 1994 usr -rw-r--r-- 1 root root 312 Aug 1 1994 welcome.msg '226 Transfer complete.' >>> ftps.quit() '221 Goodbye.' >>> rNc Cs|dk r|dk rtd|dk r0|dk r0td|dk s@|dk rVddl} | dtd||_||_|dkr|tj|j||d}||_ d|_ t ||||||| dS)Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiverzAkeyfile and certfile are deprecated, use a custom context insteadr})certfilekeyfileF) rMwarningswarnDeprecationWarningrrsslZ_create_stdlib_context ssl_versioncontext_prot_prr) rrrrrrrrrrrrrrrs(zFTP_TLS.__init__TcCs*|rt|jtjs|t||||Sr)rr"r SSLSocketauthrr)rrrrZsecurerrrrsz FTP_TLS.logincCsft|jtjrtd|jtjkr.|d}n |d}|jj |j|j d|_|jj d|j d|_ |S)z2Set up secure control connection by using TLS/SSL.zAlready using TLSzAUTH TLSzAUTH SSLZserver_hostnamer+)moder-)rr"rrrMrZ PROTOCOL_TLSrur wrap_socketrr5r-r6rgrrrrs    z FTP_TLS.authcCs0t|jtjstd|d}|j|_|S)z/Switch back to a clear-text control connection.z not using TLSZCCC)rr"rrrMrurrgrrrcccs   z FTP_TLS.ccccCs|d|d}d|_|S)zSet up secure data connection.zPBSZ 0zPROT PTrurrgrrrprot_ps  zFTP_TLS.prot_pcCs|d}d|_|S)z"Set up clear text data connection.zPROT CFrrgrrrprot_c s zFTP_TLS.prot_ccCs2t|||\}}|jr*|jj||jd}||fS)Nr)rrrrrr)rrsrrrrrrrs zFTP_TLS.ntransfercmdcCs8dt}|j||}|dddkr4t||S)Nrir[rj)rnr"rOr_rrprrrrqs  z FTP_TLS.abort)rrrT)N)rrrrrZPROTOCOL_TLS_CLIENTrrrrrrrrrrqrrrrrs      rcCs\|dddkrt|tdkrt |d }||fS) zParse the '227' response for a PASV request. Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)' Return ('host.addr.as.numbers', port#) tuple.Nr[Z227rz#(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)rvr\rB) r_227_rerrrsearchrgroupsrzr)rerrZnumbersrr.rrrr=s rcCs|dddkrt||d}|dkr2t||d|d}|dkrRt|||d||dkrrt|||d|||d}t|dkrt||d}t|d}||fS) zParse the '229' response for an EPSV request. Raises error_proto if it does not contain '(|||port|)' Return ('host.addr.as.numbers', port#) tuple.Nr[Z229(r)r rB)rfindrryrFr)reZpeerleftrightpartsrr.rrrrQs    rcCs|dddkrt||dddkr,dSd}d}t|}||kr||}|d}|dkrz||ks||dkrrq|d}||}q<|S) zParse the '257' response for a MKD or PWD request. This is a response to a MKD or PWD request: a directory name. Returns the directoryname in the 257 reply.Nr[rrBz "rr ")rrF)rerrJnrfrrrrgs  rcCs t|dS)z+Default retrlines callback to print a line.N)r:)rRrrrr~srrIc Cs|s|}d|}||||t|d\}}||||d|}|dddkrdt|d|}|dddkrt||dS)z+Copy file from one FTP-instance to another.zTYPE rzSTOR Nr[>125rRETR )rurrtr|rrh) sourceZ sourcenametargetZ targetnamerZ sourcehostZ sourceportZtreplyZsreplyrrrftpcps   rc Csttjdkr"ttjtdddl}d}d}tjddkrR|d}tjd=q2tjddddkrtjddd}tjd=tjd}t|}| |d}}}z||}Wn(t k r|dk rtj dYn:Xz| |\}}}Wn"tk rtj d YnX||||tjddD]} | ddd kr`|| ddnt| dddkrd } | ddr| d | dd} || } n0| d kr||j n|d| tjj dq6|dS)zTest program. Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ... -d dir -l list -p password r}rNr z-dz-rrz5Could not open account file -- using anonymous login.z$No account -- using anonymous login.z-lZCWDrz-pri)rFr/argvr:testrexitnetrcrr>r%stderrwriteZauthenticatorsKeyErrorrrrtrAr?rstdoutr$) rr9ZrcfilerZftpZuseridrrZnetrcobjr6rsrerrrrsV           r__main__)rr)%rr/r1r__all__rorr Exceptionr rrrrr%r&rrNrnrr ImportErrorrrrrZSSLErrorrrrrrrrrrrrrrrsR&   Z  |  9