b374k
m1n1 1.01
Apache/2.2.15 (CentOS)
Linux obd60-6c49958d75-2q7cw 5.4.0-174-generic #193-Ubuntu SMP Thu Mar 7 14:29:28 UTC 2024 x86_64
uid=48(apache) gid=48(apache) groups=48(apache)
server ip : 172.67.192.52 | your ip : 10.244.126.0
safemode OFF
 >  / usr / lib64 / python2.6 /
Filename/usr/lib64/python2.6/ftplib.pyo
Size27.83 kb
Permissionrw-r--r--
Ownerapache
Create time23-Dec-2025 17:41
Last modified20-Jun-2019 19:45
Last accessed22-Apr-2026 05:28
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
Ñò
§ÚêLc @s¹dZddkZddkZy5ddkZeZ[ddklZee_[Wnej
oddkZnXddklZddgZdZ dZ
d Z d
e fd ��YZ
d e
fd
��YZde
fd��YZde
fd��YZde
fd��YZe
eefZdZdfd��YZead�Zead�Zd�Zd�Zd�Zddd�Zdfd��YZ d�Z!e"d jo e!�ndS(!sSAn 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
iÿÿÿÿN(tgetfqdn(t_GLOBAL_DEFAULT_TIMEOUTtFTPtNetrciii tErrorcBseZRS((t__name__t
__module__(((s/usr/lib64/python2.6/ftplib.pyR>st error_replycBseZRS((RR(((s/usr/lib64/python2.6/ftplib.pyR?st
error_tempcBseZRS((RR(((s/usr/lib64/python2.6/ftplib.pyR@st
error_permcBseZRS((RR(((s/usr/lib64/python2.6/ftplib.pyR Ast error_protocBseZRS((RR(((s/usr/lib64/python2.6/ftplib.pyR
Bss
cBsÓeZdZdZdZeZeZd,Z
d,Z d,Z dZ
dddded�Zdddd�Zd�Zd�ZeZd �Zd
�Zd �Zd �Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d,d�Z#d,d�Z$dddd�Z%dd,d�Z&d,d�Z'dd,d�Z(d,d�Z)d �Z*d!�Z+d"�Z,d#�Z-d$�Z.d%�Z/d&�Z0d'�Z1d(�Z2d)�Z3d*�Z4d+�Z5RS(-suAn 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.
iticCsC||_|o/|i|�|o|i|||�q?ndS(N(ttimeouttconnecttlogin(tselfthosttusertpasswdtacctR ((s/usr/lib64/python2.6/ftplib.pyt__init__ss
 
iüÿÿcCs¬|djo
||_n|djo
||_n|djo
||_nti|i|if|i�|_|ii|_|iid�|_ |i
�|_ |i S(s¶Connect to host. Arguments are:
- host: hostname to connect to (string, default previous host)
- port: port to connect to (integer, default previous port)
R iiüÿÿtrb( RtportR tsockettcreate_connectiontsocktfamilytaftmakefiletfiletgetresptwelcome(RRRR ((s/usr/lib64/python2.6/ftplib.pyR
{s





$cCs*|iodG|i|i�GHn|iS(s`Get the welcome message from the server.
(this is read and squirreled away by connect())s *welcome*(t debuggingtsanitizeR(R((s/usr/lib64/python2.6/ftplib.pyt
getwelcome�s
cCs
||_dS(sðSet 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(R (Rtlevel((s/usr/lib64/python2.6/ftplib.pytset_debuglevel�scCs
||_dS(s�Use 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(t
passiveserver(Rtval((s/usr/lib64/python2.6/ftplib.pytset_pasv�scCs�|d djp|d djobt|�}x1|djo#||ddjo|d}q1W|d d|d||}nt|�S(Nispass sPASS is
t*(tlentrepr(Rtsti((s/usr/lib64/python2.6/ftplib.pyR!£s" ""cCsD|t}|idjodG|i|�GHn|ii|�dS(Nis*put*(tCRLFR R!Rtsendall(Rtline((s/usr/lib64/python2.6/ftplib.pytputline¬s
cCs1|iodG|i|�GHn|i|�dS(Ns*cmd*(R R!R0(RR/((s/usr/lib64/python2.6/ftplib.pytputcmd²s
cCs¿|ii|id�}t|�|ijotd|i��n|idjodG|i|�GHn|p
t�n|dtjo|d }n |dtjo|d }n|S(Nisgot more than %d bytess*get*iþÿÿÿiÿÿÿÿ( RtreadlinetmaxlineR)RR R!tEOFErrorR-(RR/((s/usr/lib64/python2.6/ftplib.pytgetline¸s
cCs||i�}|dd!djoX|d }xK|i�}|d|}|d |jo|dd!djoPq-q-n|S(Niit-s
(R5(RR/tcodetnextline((s/usr/lib64/python2.6/ftplib.pyt getmultilineÇs 
  cCs�|i�}|iodG|i|�GHn|d |_|d }|d jo|S|djo
t|�n|djo
t|�nt|�dS(
Ns*resp*iit1t2t3t4t5(R:R;R<(R9R R!tlastrespRR R
(Rtresptc((s/usr/lib64/python2.6/ftplib.pyRÕs 







cCs.|i�}|d djo
t|�n|S(s%Expect a response beginning with '2'.iR;(RR(RR@((s/usr/lib64/python2.6/ftplib.pytvoidrespâs 
cCsqdt}|idjodG|i|�GHn|ii|t�|i�}|d d jo
t|�ndS(
süAbort 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.tABORis *put urgent*it426t225t226N(RDRERF(R-R R!RR.tMSG_OOBR9R
(RR/R@((s/usr/lib64/python2.6/ftplib.pytabortés
 cCs|i|�|i�S(s'Send a command and return the response.(R1R(Rtcmd((s/usr/lib64/python2.6/ftplib.pytsendcmdõs
cCs|i|�|i�S(s8Send a command and expect a response beginning with '2'.(R1RB(RRI((s/usr/lib64/python2.6/ftplib.pytvoidcmdús
cCsY|id�}t|d�t|d�g}||}ddi|�}|i|�S(sUSend a PORT command with the current host and the given
port number.
t.isPORT t,(tsplitR*tjoinRK(RRRthbytestpbytestbytesRI((s/usr/lib64/python2.6/ftplib.pytsendportÿs
 
cCs�d}|itijo
d}n|itijo
d}n|djo
td�ndt|�|t|�dg}ddi|�}|i|�S(sDSend a EPRT command with the current host and the given port number.iiisunsupported address familyR sEPRT t|(RRtAF_INETtAF_INET6R
R*RORK(RRRRtfieldsRI((s/usr/lib64/python2.6/ftplib.pytsendeprt s



!c Cs]d}d}x¤tidd|itidti�D]{}|\}}}}}y&ti|||�}|i|�Wn6tij
o'}|o|i�nd}q4nXPq4W|pti|�n|i d�|i
�d} |i i
�d}
|iti jo|i
|
| �} n|i|
| �} |itj o|i|i�n|S(s3Create a new socket and send a PORT command for it.s!getaddrinfo returns an empty listiiN(tNoneRt getaddrinfoRt SOCK_STREAMt
AI_PASSIVEtbindterrortclosetlistent getsocknameRRURSRXR Rt
settimeout( RtmsgRtresRtsocktypetprotot canonnametsaRRR@((s/usr/lib64/python2.6/ftplib.pytmakeports2(
cCsc|itijot|id��\}}n(t|id�|ii��\}}||fS(NtPASVtEPSV(RRRUtparse227RJtparse229Rt getpeername(RRR((s/usr/lib64/python2.6/ftplib.pytmakepasv2s'c
Cs�d}|io¡|i�\}}ti||f|i�}|dj o|id|�n|i|�}|ddjo|i�}n|ddjo
t|�qcn³|i �}|dj o|id|�n|i|�}|ddjo|i�}n|ddjo
t|�n|i
�\}} |it j o|i |i�n|d djot
|�}n||fS(s¦Initiate 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.
sREST %siR;R:it150N(RYR%RoRRR RJRRRitacceptRRbtparse150(
RRItresttsizeRRtconnR@Rtsockaddr((s/usr/lib64/python2.6/ftplib.pyt ntransfercmd9s2

 

cCs|i||�dS(s0Like ntransfercmd() but returns only the socket.i(Rw(RRIRs((s/usr/lib64/python2.6/ftplib.pyt transfercmdkscCsà|p
d}n|p
d}n|p
d}n|djo|d jo|d}n|id|�}|ddjo|id|�}n|ddjo|id |�}n|dd
jo
t|�n|S( sLogin, default anonymous.t anonymousR R6s
anonymous@sUSER iR<sPASS sACCT R;(R R6(RJR(RRRRR@((s/usr/lib64/python2.6/ftplib.pyRos 



i cCs^|id�|i||�}x(|i|�}|pPn||�q"|i�|i�S(sÆRetrieve 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.
sTYPE I(RKRxtrecvR_RB(RRItcallbackt blocksizeRsRutdata((s/usr/lib64/python2.6/ftplib.pyt
retrbinary�s


cCs"|d
jo
t}n|id�}|i|�}|id�}x½|i|id�}t|�|ijotd|i��n|i djodGt
|�GHn|pPn|dt jo|d }n |dd jo|d }n||�qG|i �|i �|i
�S( snRetrieve data in line mode. A new port is created for you.

Args:
cmd: A RETR, LIST, NLST, or MLSD 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.
sTYPE ARisgot more than %d bytesis*retr*iþÿÿÿiÿÿÿÿs
N(RYt
print_lineRJRxRR2R3R)RR R*R-R_RB(RRIR{R@RutfpR/((s/usr/lib64/python2.6/ftplib.pyt retrlines�s*




cCss|id�|i|�}x@|i|�}|pPn|i|�|o||�qq|i�|i�S(sStore 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
on each block of data after it is sent. [default: None]

Returns:
The response code.
sTYPE I(RKRxtreadR.R_RB(RRIR�R|R{Rutbuf((s/usr/lib64/python2.6/ftplib.pyt
storbinary¼s


cCså|id�|i|�}x²|i|id�}t|�|ijotd|i��n|pPn|dtjo-|dtjo|d }n|t}n|i|�|o||�qq|i�|i �S(skStore 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
on each line after it is sent. [default: None]

Returns:
The response code.
sTYPE Aisgot more than %d bytesiþÿÿÿiÿÿÿÿ(
RKRxR2R3R)RR-R.R_RB(RRIR�R{RuR�((s/usr/lib64/python2.6/ftplib.pyt storlinesÔs"


cCsd|}|i|�S(sSend new account name.sACCT (RK(RtpasswordRI((s/usr/lib64/python2.6/ftplib.pyRïs
cGsBd}x|D]}|d|}q
Wg}|i||i�|S(sBReturn a list of files in a given directory (default the current).tNLSTt (R�tappend(RtargsRItargtfiles((s/usr/lib64/python2.6/ftplib.pytnlstôscGs�d}d}|do6t|d�td�jo|d |d}}nx'|D]}|o|d|}qTqTW|i||�dS(sList 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.)tLISTiÿÿÿÿR R�N(RYttypeR�(RR�RItfuncR�((s/usr/lib64/python2.6/ftplib.pytdirýs(cCsB|id|�}|ddjo
t|�n|id|�S(sRename a file.sRNFR iR<sRNTO (RJRRK(RtfromnamettonameR@((s/usr/lib64/python2.6/ftplib.pytrename s
cCs6|id|�}|d djo|St|�dS(sDelete a file.sDELE it250t200N(R�R�(RJR(RtfilenameR@((s/usr/lib64/python2.6/ftplib.pytdeletescCs�|djoLy|id�SWqptj
o(}|idd djo�qUqpXn|djo
d}nd|}|i|�S( sChange to a directory.s..tCDUPiit500R RLsCWD (RKR R�(RtdirnameRcRI((s/usr/lib64/python2.6/ftplib.pytcwds



cCsm|id|�}|d djoE|di�}yt|�SWqittfj
ot|�SXndS(sRetrieve the size of a file.sSIZE it213N(RJtstriptintt
OverflowErrort
ValueErrortlong(RR�R@R+((s/usr/lib64/python2.6/ftplib.pyRt(scCs|id|�}t|�S(s+Make a directory, return its full pathname.sMKD (RJtparse257(RR�R@((s/usr/lib64/python2.6/ftplib.pytmkd3scCs|id|�S(sRemove a directory.sRMD (RK(RR�((s/usr/lib64/python2.6/ftplib.pytrmd8scCs|id�}t|�S(s!Return current working directory.tPWD(RJR£(RR@((s/usr/lib64/python2.6/ftplib.pytpwd<scCs|id�}|i�|S(sQuit, and close the connection.tQUIT(RKR_(RR@((s/usr/lib64/python2.6/ftplib.pytquitAs
cCs<|io.|ii�|ii�d|_|_ndS(s8Close the connection without assuming anything about it.N(RR_RRY(R((s/usr/lib64/python2.6/ftplib.pyR_Gs


N(6RRt__doc__R RtFTP_PORTRtMAXLINER3RYRRRR%RRR
R"R$tdebugR'R!R0R1R5R9RRBRHRJRKRSRXRiRoRwRxRR~R�R�R�RR�R�R�R�R�RtR¤R¥R§R©R_(((s/usr/lib64/python2.6/ftplib.pyRNsb         
  

  2       
   cCs¯|d djo
t|�ntdjo%ddk}|id|i�anti|�}|pdS|id�}yt|�SWn t t
fj
ot |�SXdS(s�Parse the '150' response for a RETR request.
Returns the expected transfer size or None; size is not guaranteed to
be present in the 150 message.
iRpiÿÿÿÿNs150 .* \((\d+) bytes\)i( Rt_150_reRYtretcompilet
IGNORECASEtmatchtgroupR�R R¡R¢(R@R¯tmR+((s/usr/lib64/python2.6/ftplib.pyRrQs

 cCs¸|d djo
t|�ntdjoddk}|id�anti|�}|p
t|�n|i�}di|d �}t |d�d>t |d �}||fS(
s¢Parse 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.it227iÿÿÿÿNs#(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)RLiii(
Rt_227_reRYR¯R°tsearchR
tgroupsROR�(R@R¯R´tnumbersRR((s/usr/lib64/python2.6/ftplib.pyRlhs

 
 "cCs|d djo
t|�n|id�}|djo
t|�n|id|d�}|djo
t|�n||d||djo
t|�n||d|!i||d�}t|�djo
t|�n|d}t|d�}||fS(s�Parse the '229' response for a EPSV request.
Raises error_proto if it does not contain '(|||port|)'
Return ('host.addr.as.numbers', port#) tuple.it229t(it)ii(RtfindR
RNR)R�(R@tpeertlefttrighttpartsRR((s/usr/lib64/python2.6/ftplib.pyRm|s 





"

cCsÄ|d djo
t|�n|dd!djodSd}d}t|�}xn||jo`||}|d}|djo1||jp||djoPn|d}n||}qRW|S(s¤Parse 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.it257is "R it"(RR)(R@R�R,tnRA((s/usr/lib64/python2.6/ftplib.pyR£�s"
 



cCs |GHdS(s+Default retrlines callback to print a line.N((R/((s/usr/lib64/python2.6/ftplib.pyR©sR tIc CsÔ|p
|}nd|}|i|�|i|�t|id��\}}|i||�|id|�}|d d jo
t�n|id|�}|d d
jo
t�n|i�|i�dS( s+Copy file from one FTP-instance to another.sTYPE RjsSTOR it125RpsRETR N(RÆs150(RÆs150(RKRlRJRSR
RB( tsourcet
sourcenamettargett
targetnameR�t
sourcehostt
sourceportttreplytsreply((s/usr/lib64/python2.6/ftplib.pytftpcp®s






cBsPeZdZdZdZdZdd�Zd�Zd�Z d�Z
d�Z RS(sÃClass to parse & provide access to 'netrc' format files.

See the netrc(4) man page for information on the file format.

WARNING: This class is obsolete -- use module netrc instead.

cCs|djo=dtijo tiitidd�}qJtd�nh|_h|_t|d�}d}x�|i �}|pPn|o!|i
�o|i |�qtn%|ot |�|i|<d}n|i
�}d}} }
} d} d}
xC|
t|�jo/||
}|
dt|�jo||
d}nd}|djo
d} nÒ|djo!|o|i�}|
d}
n¤|d jo|o|} |
d}
n||d
jo|o|}
|
d}
nT|d jo|o|} |
d}
n,|d jo|o|}g}d}Pn|
d}
qW| o=| p|i|_|
p|i|_| p|i|_n|ok||ijoA|i|\}}}| p|} |
p|}
| p|} n| |
| f|i|<qtqt|i�dS(
NtHOMEs.netrcs!specify file to load or set $HOMEtriitdefaulttmachineRR�taccounttmacdef(RYtostenvirontpathROtIOErrort
_Netrc__hostst_Netrc__macrostopenR2R�R�ttupleRNR)tlowert_Netrc__defusert_Netrc__defpasswdt_Netrc__defacctR_(RR�R�tin_macroR/t macro_linest
macro_nametwordsRRRRRÒR,tw1tw2tousertopasswdtoacct((s/usr/lib64/python2.6/ftplib.pyRÍs|


   

 


 

cCs
|ii�S(s4Return a list of hosts mentioned in the .netrc file.(RÚtkeys(R((s/usr/lib64/python2.6/ftplib.pyt get_hostsscCs�|i�}d}}}||ijo|i|\}}}n|p|i}|p|i}|p|i}|||fS(s�Returns login information for the named host.

The return value is a triple containing userid,
password, and the accounting field.

N(RÞRYRÚRßRàRá(RRRRR((s/usr/lib64/python2.6/ftplib.pyt get_accounts cCs
|ii�S(s)Return a list of all defined macro names.(RÛRë(R((s/usr/lib64/python2.6/ftplib.pyt
get_macros"scCs |i|S(s6Return a sequence of lines which define a named macro.(RÛ(Rtmacro((s/usr/lib64/python2.6/ftplib.pyt get_macro&sN( RRRªRYRßRàRáRRìRíRîRð(((s/usr/lib64/python2.6/ftplib.pyRÁs A   c CsHtti�djotiGHtid�nd}d}x-tiddjo|d}tid=q>Wtidd djotidd}tid=ntid}t|�}|i|�d}}}yt |�}Wn4t
j
o(|dj oti i d�q_nDXy|i
|�\}}}Wn#tj
oti i d�nX|i|||�xÅtidD]¶}|d d jo|i|d�q�|d djo:d
} |do| d |d} n|i| �}
q�|d jo|i|i �q�|id
|tii d�q�W|i�dS(s�Test program.
Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...

-d dir
-l list
-p password
iiis-ds-rR s5Could not open account file -- using anonymous login.s$No account -- using anonymous login.s-ltCWDR�s-psRETR iN(R)tsystargvttestRªtexitRYRR$RRÙtstderrtwriteRítKeyErrorRR�RJR'R%R~tstdoutR©( R trcfileRtftptuseridRRtnetrcRRIR@((s/usr/lib64/python2.6/ftplib.pyRô,sR 

 

   

t__main__(#RªRÖRòtSOCKSRRt ImportErrorRt__all__RGR«R¬t ExceptionRRRR R
RÙR4t
all_errorsR-RRYR®RrR¶RlRmR£RRÏRRôR(((s/usr/lib64/python2.6/ftplib.pyt<module>sL     ÿÿ     k 7