# -*- coding:utf-8 -*-
# !/usr/bin/env python3
# name : Alenx
from ftplib import FTP
def ftpconnect():
ftp_server = '10.40.0.11'
username = 'ftpadmin'
password = 'ftpadmin'
ftp = FTP()
ftp.set_debuglevel(2)
ftp.connect(ftp_server, 21)
ftp.login(username, password)
return ftp
def downloadfile():
remotepath = "/home/pub/dog.jpg"
ftp = ftpconnect()
print(ftp.getwelcome())
bufsize = 1024
localpath = 'f:\\test\\dog.jpg'
fp = open(localpath, 'wb')
ftp.retrbinary('RETR ' + remotepath, fp.write, bufsize)
ftp.set_debuglevel(0)
fp.close()
ftp.quit()
def uploadfile():
remotepath = "/opt/ftpadmin/redis.sh"
ftp = ftpconnect()
bufsize = 1024
localpath = '/Users/admin/redis.sh'
fp = open(localpath, 'rb')
ftp.storbinary('STOR ' + remotepath, fp, bufsize)
ftp.set_debuglevel(0)
fp.close()
ftp.quit()
def getList():
ftp = ftpconnect()
print('*' * 40)
ftp.dir()
ftp.dir('/aaa/')
print('+' * 40)
if __name__ == "__main__":
# uploadfile()
getList()
Python--利用ftplib自动上传/下载文件
最新推荐文章于 2024-02-20 17:53:18 发布