python操作ftp文件
Posted forcheny
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python操作ftp文件相关的知识,希望对你有一定的参考价值。
from ftplib import FTP ftp = FTP(‘ftp.abc.com‘) ftp.login(user=‘username‘, passwd=‘********‘) ftp.cwd(‘/path‘) #entry directory path # ftp.retrlines(‘LIST‘) files = ftp.dir() print(files) ftp.quit() def grabFile(): """ Download filename to local current folder with name localfile """ filename = ‘CAP2‘ localfile = open(‘CAP2COPY‘, ‘wb‘) ftp.retrbinary(‘RETR ‘ + filename, localfile.write, 1024) print(‘Download is finished!‘) ftp.quit() localfile.close() # grabFile() def placeFile(): """ Upload filename to ftp server with same filename """ filename = ‘example.ini‘ ftp.storbinary(‘STOR ‘+filename, open(filename, ‘rb‘)) ftp.quit() # placeFile() def deleteFile(): """ Delete filename from ftp server """ filename = ‘example.ini‘ ftp.delete(filename) files = ftp.dir() print(files) ftp.quit() # deleteFile()
参考:
https://www.pythonforbeginners.com/code-snippets-source-code/how-to-use-ftp-in-python/
https://pythonprogramming.net/ftp-transfers-python-ftplib/
以上是关于python操作ftp文件的主要内容,如果未能解决你的问题,请参考以下文章
python实现从FTP下载文件通过多线程同时分发到多台机器