相关疑难解决方法(0)

如何使用Python ftplib通过FTP下载文件

我有以下代码,可以轻松连接到FTP服务器并打开一个zip文件.我想将该文件下载到本地系统.怎么做?

# Open the file for writing in binary mode
print 'Opening local file ' + filename
file = open(filename, 'wb')

# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command

print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)

# Clean up time
print 'Closing file ' + filename
file.close()
Run Code Online (Sandbox Code Playgroud)

python ftplib

60
推荐指数
6
解决办法
10万
查看次数

标签 统计

ftplib ×1

python ×1