|
Size: 1781
Comment:
|
← Revision 8 as of 2023-10-11 20:13:45 ⇥
Size: 5216
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 6: | Line 6: |
---- == Usage == {{{ from ftplib import FTP # connect conn = FTP('ftp.example.com') conn.login(user='example', passwd='secret') # list files conn.dir('folder1') # or conn.cwd('folder1') conn.dir() # download a file with open('destination.txt', 'wb') as f: ftp.retrbinary('RETR source.txt', f.write, blocksize=1024) # upload a file with open('source.txt', 'b') as f: ftp.storbinary('STOR source.txt', f) # close connection conn.quit() }}} |
|
| Line 17: | Line 48: |
==== Abort ==== ---- |
'''`ftplib.FTP`''' is the core client object for the module. See the example above. |
| Line 25: | Line 52: |
| ==== Close ==== | ==== Methods ==== |
| Line 27: | Line 54: |
| ---- | The following methods are available as interfaces to established [[Protocols/FTP|FTP]] commands: |
| Line 29: | Line 56: |
| ||'''Method''' ||'''Command''' || ||`cwd(dir)` ||`CWD` || ||`delete(fn)` ||`DELE` || ||`dir(dir)` ||`LIST` || ||`mkd(dir)` ||`MKD` || ||`mlsd(dir)` ||`MLSD` || ||`nlst(dir)` ||`NLST` || ||`pwd()` ||`PWD` || ||`quit()` ||`QUIT` || ||`rename(old, new)`||`RNFR`, `RNTO`|| ||`rmd(dir)` ||`RMD` || ||`size(fn)` ||`SIZE` || |
|
| Line 30: | Line 69: |
| The following other methods are also exposed. | |
| Line 31: | Line 71: |
| ==== Connect ==== ---- ==== Cwd ==== ---- ==== Delete ==== ---- ==== Dir ==== ---- ==== GetWelcome ==== ---- ==== Login ==== ---- ==== Mkd ==== ---- ==== Mlsd ==== ---- ==== Nlst ==== ---- ==== NTransferCmd ==== ---- ==== Pwd ==== ---- ==== Quit ==== ---- ==== Rename ==== ---- ==== RetrBinary ==== ---- ==== RetrLines ==== ---- ==== Rmd ==== ---- ==== SendCmd ==== ---- ==== Set_DebugLevel ==== ---- ==== Set_Pasv ==== ---- ==== Size ==== ---- ==== StorBinary ==== ---- ==== StorLines ==== ---- ==== TransferCmd ==== ---- ==== VoidCmd ==== |
||'''Method''' ||'''Meaning''' || ||`abort()` ||''try'' to abort an ongoing file transfer; leverages the `ABOR` command, which actually aborts the last FTP command || ||`close()` ||see above example || ||`connect()` ||if an `ftplib.FTP` object was not instantiated with a host, call this method like `FTP.connect(host='ftp.example.com', port=21, timeout=300)`|| ||`getwelcome()` ||return the server's welcome message || ||`login()`' ||see above example || ||`ntransfercmd()` || || ||`retrbinary()` ||see above example || ||`retrlines()` || || ||`sendcmd()` ||send an FTP command and return the response as a string || ||`set_debuglevel()`|| || ||`set_pasv()` || || ||`storbinary()` ||see above example || ||`storlines()` || || ||`transfercmd()` || || ||`voidcmd()` ||send an FTP command and raise `ftplib.error_reply` if a response code outside of 200-299 is received || |
| Line 177: | Line 94: |
| A subclass of `ftplib.FTP` with additional methods and properties. | |
| Line 178: | Line 96: |
| ||'''Method'''||'''Meaning''' || ||`auth()` ||upgrade to secure connection || ||`ccc()` ||revert to plaintext connection || ||`prot_c()` ||setup plaintext (''clear'') connection || ||`prot_p()` ||setup secure (''protected'') connection|| |
|
| Line 179: | Line 102: |
| ==== Auth ==== ---- ==== Ccc ==== ---- ==== Prot_P ==== ---- ==== Prot_C ==== ---- ==== Ssl_Version ==== |
||'''Property'''||'''Meaning''' || ||`ssl_version` ||version of SSL/TLS to use (default: `ssl.PROTOCOL_SSLv23`)|| |
| Line 211: | Line 111: |
=== All_Errors === A tuple of the following exceptions. ---- === Error_Reply === Raised when an unexpected reply is received. ---- === Error_Temp === Raised when a temporary error (400-499) is received. ---- === Error_Perm === Raised when a permanent error (500-599) is received. ---- === Error_Proto === Raised when an improperly-formatted reply is received. |
||'''Exception''' ||'''Meaning''' || ||`ftplib.all_errors` ||tuple of all following errors || ||`ftplib.error_reply`||unexpected response is received || ||`ftplib.error_temp` ||temporary error (400-499) || ||`ftplib.error_perm` ||permanent error (500-599) || ||`ftplib.error_proto`||improperly-formatted response is received|| |
Python FtpLib
The ftplib module is an FTP client.
Contents
Usage
from ftplib import FTP
# connect
conn = FTP('ftp.example.com')
conn.login(user='example', passwd='secret')
# list files
conn.dir('folder1')
# or
conn.cwd('folder1')
conn.dir()
# download a file
with open('destination.txt', 'wb') as f:
ftp.retrbinary('RETR source.txt', f.write, blocksize=1024)
# upload a file
with open('source.txt', 'b') as f:
ftp.storbinary('STOR source.txt', f)
# close connection
conn.quit()
Classes
Ftp
ftplib.FTP is the core client object for the module. See the example above.
Methods
The following methods are available as interfaces to established FTP commands:
Method |
Command |
cwd(dir) |
CWD |
delete(fn) |
DELE |
dir(dir) |
LIST |
mkd(dir) |
MKD |
mlsd(dir) |
MLSD |
nlst(dir) |
NLST |
pwd() |
PWD |
quit() |
QUIT |
rename(old, new) |
RNFR, RNTO |
rmd(dir) |
RMD |
size(fn) |
SIZE |
The following other methods are also exposed.
Method |
Meaning |
abort() |
try to abort an ongoing file transfer; leverages the ABOR command, which actually aborts the last FTP command |
close() |
see above example |
connect() |
if an ftplib.FTP object was not instantiated with a host, call this method like FTP.connect(host='ftp.example.com', port=21, timeout=300) |
getwelcome() |
return the server's welcome message |
login()' |
see above example |
ntransfercmd() |
|
retrbinary() |
see above example |
retrlines() |
|
sendcmd() |
send an FTP command and return the response as a string |
set_debuglevel() |
|
set_pasv() |
|
storbinary() |
see above example |
storlines() |
|
transfercmd() |
|
voidcmd() |
send an FTP command and raise ftplib.error_reply if a response code outside of 200-299 is received |
Ftp_Tls
A subclass of ftplib.FTP with additional methods and properties.
Method |
Meaning |
auth() |
upgrade to secure connection |
ccc() |
revert to plaintext connection |
prot_c() |
setup plaintext (clear) connection |
prot_p() |
setup secure (protected) connection |
Property |
Meaning |
ssl_version |
version of SSL/TLS to use (default: ssl.PROTOCOL_SSLv23) |
Exceptions
Exception |
Meaning |
ftplib.all_errors |
tuple of all following errors |
ftplib.error_reply |
unexpected response is received |
ftplib.error_temp |
temporary error (400-499) |
ftplib.error_perm |
permanent error (500-599) |
ftplib.error_proto |
improperly-formatted response is received |
See also
Python ftplib module documentation
