zoukankan      html  css  js  c++  java
  • 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/

    转载于:https://www.cnblogs.com/forcheny/p/10209615.html

  • 相关阅读:
    1043. 输出PATest(20)
    1042. 字符统计(20)
    1041. 考试座位号(15)
    1040. 有几个PAT(25)
    1035. 插入与归并(25)
    栈:火车进站
    ABC Fennec VS. Snuke
    费解的开关
    最短Hamilton路径
    built?
  • 原文地址:https://www.cnblogs.com/twodog/p/12135370.html
Copyright © 2011-2022 走看看