例1,从远程ftp服务器上下载文件
代码:
#!/usr/bin/python
#
#site: www.jb200.com
import ftplib
ftp = ftblib.FTP("ftp.yourServer.com")
ftp.login("username", "password")
filename = "index.html"
ftp.storlines("STOR " + filename, open(filename))
filename="app.exe"
ftp.storbinary("STOR " + filename, open(filename, "rb"), 1024)
例2,根据ftp传输调试bug信息
代码:
#!/usr/bin/python
#
#site: www.jb200.com
ftp = ftplib.FTP('127.0.0.1', 'book', 'bookpw')
f = open("MyPycFile.pyc", "wb")
ftp.set_pasv(1)
ftp.set_debuglevel(1)
ftp.retrbinary("RETR AutoIndent.pyc", f.write)