码迷,mamicode.com
首页 > 编程语言 > 详细

python操作ftp文件

时间:2019-01-02 19:07:55      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:highlight   pass   username   file   cal   files   ram   from   .com   

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文件

标签:highlight   pass   username   file   cal   files   ram   from   .com   

原文地址:https://www.cnblogs.com/forcheny/p/10209615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!