通过Python 下载 FTP 服务器上的文件
环境 Python3.7
import os
from ftplib import FTP
host = '192.168.131.154'
ftp = FTP()
ftp.connect(host, 21)
useranme = 'test'
password = 'test@123'
ftp.login(useranme,password)
ftppath = '/DOC/'
ftp.cwd(ftppath)
filebefore = ftp.nlst()
localpath = 'D:\\Documents\\'
os.chdir(localpath)
fileafter = []
for fileone in filebefore:
if not os.path.exists(fileone):
fileafter.append(fileone)
for filetwo in fileafter:
file_handle = open(filetwo, 'wb').write
ftp.retrbinary('RETR %s' % filetwo, file_handle, blocksize=1024)
ftp.quit()
print(os.listdir())