更新mrs_connect

This commit is contained in:
gqh
2023-01-11 15:04:37 +08:00
parent 8e51654f17
commit 381d6ca9a5
4 changed files with 85 additions and 53 deletions

View File

@@ -15,26 +15,30 @@ class FtpController():
ftp = FTP()
def __init__(self, host="192.168.50.202", port=21, username="ftpuser", password="123456"):
def __init__(self, host, port, username, password):
try:
self.ftp.connect(host, port)
self.ftp.login(username, password)
logging.info("连接成功: ")
logging.info("ftp连接成功")
except:
logging.info("连接失败: ")
logging.info("ftp连接失败")
# 下载目录下的文件
def download_file_tree(self, target_dir, serverdir):
if not os.path.exists(serverdir):
os.makedirs(serverdir)
try:
logging.info("进入FTP目录 ")
self.ftp.cwd(target_dir) # 切换工作路径
logging.info('FTP目录:%s' % target_dir)
remotenames = self.ftp.nlst()
logging.info('FTP目录文件:%s' % remotenames)
for file in remotenames:
server = os.path.join(serverdir, file)
if file.find(".") != -1:
self.download_file(server, file)
else:
return
except:
return False
# 下载指定目录下的指定文件
def download_file(self, serverfile, remotefile):