Commit 84ef6a18 authored by 宋朋's avatar 宋朋

update

parent 47a5a1b2
......@@ -52,89 +52,89 @@ class MyFTP:
self.deal_error("FTP 连接或登录失败 ,错误信息为:%s" % err)
pass
# def is_same_size(self, local_file, remote_file):
# """判断远程文件和本地文件大小是否一致
# 参数:
# local_file: 本地文件
# remote_file: 远程文件
# """
# try:
# remote_file_size = self.ftp.size(remote_file)
# except Exception as err:
#
# remote_file_size = -1
#
# try:
# local_file_size = os.path.getsize(local_file)
# except Exception as err:
# local_file_size = -1
#
# self.debug_print('local_file_size:%d , remote_file_size:%d' % (local_file_size, remote_file_size))
# if remote_file_size == local_file_size:
# return 1
# else:
# return 0
# def download_file(self, local_file, remote_file):
# """从ftp下载文件
# 参数:
# local_file: 本地文件
# remote_file: 远程文件
# """
# self.debug_print("download_file()---> local_path = %s ,remote_path = %s" % (local_file, remote_file))
#
# if self.is_same_size(local_file, remote_file):
# self.debug_print('%s 文件大小相同,无需下载' % local_file)
# return
# else:
# try:
# self.debug_print('>>>>>>>>>>>>下载文件 %s ... ...' % local_file)
# buf_size = 1024
# file_handler = open(local_file, 'wb')
# self.ftp.retrbinary('RETR %s' % remote_file, file_handler.write, buf_size)
# file_handler.close()
# except Exception as err:
# self.debug_print('下载文件出错,出现异常:%s ' % err)
# return
# def download_file_tree(self, local_path, remote_path):
# """从远程目录下载多个文件到本地目录
# 参数:
# local_path: 本地路径
# remote_path: 远程路径
# """
# print("download_file_tree()---> local_path = %s ,remote_path = %s" % (local_path, remote_path))
# try:
# self.ftp.cwd(remote_path)
# except Exception as err:
# self.debug_print('远程目录%s不存在,继续...' % remote_path + " ,具体错误描述为:%s" % err)
# return
#
# if not os.path.isdir(local_path):
# self.debug_print('本地目录%s不存在,先创建本地目录' % local_path)
# os.makedirs(local_path)
#
# self.debug_print('切换至目录: %s' % self.ftp.pwd())
#
# self.file_list = []
# # 方法回调
# self.ftp.dir(self.get_file_list)
#
# remote_names = self.file_list
# self.debug_print('远程目录 列表: %s' % remote_names)
# for item in remote_names:
# file_type = item[0]
# file_name = item[1]
# local = os.path.join(local_path, file_name)
# if file_type == 'd':
# print("download_file_tree()---> 下载目录: %s" % file_name)
# self.download_file_tree(local, file_name)
# elif file_type == '-':
# print("download_file()---> 下载文件: %s" % file_name)
# self.download_file(local, file_name)
# self.ftp.cwd("..")
# self.debug_print('返回上层目录 %s' % self.ftp.pwd())
# return True
def is_same_size(self, local_file, remote_file):
"""判断远程文件和本地文件大小是否一致
参数:
local_file: 本地文件
remote_file: 远程文件
"""
try:
remote_file_size = self.ftp.size(remote_file)
except Exception as err:
remote_file_size = -1
try:
local_file_size = os.path.getsize(local_file)
except Exception as err:
local_file_size = -1
self.debug_print('local_file_size:%d , remote_file_size:%d' % (local_file_size, remote_file_size))
if remote_file_size == local_file_size:
return 1
else:
return 0
def download_file(self, local_file, remote_file):
"""从ftp下载文件
参数:
local_file: 本地文件
remote_file: 远程文件
"""
self.debug_print("download_file()---> local_path = %s ,remote_path = %s" % (local_file, remote_file))
if self.is_same_size(local_file, remote_file):
self.debug_print('%s 文件大小相同,无需下载' % local_file)
return
else:
try:
self.debug_print('>>>>>>>>>>>>下载文件 %s ... ...' % local_file)
buf_size = 1024
file_handler = open(local_file, 'wb')
self.ftp.retrbinary('RETR %s' % remote_file, file_handler.write, buf_size)
file_handler.close()
except Exception as err:
self.debug_print('下载文件出错,出现异常:%s ' % err)
return
def download_file_tree(self, local_path, remote_path):
"""从远程目录下载多个文件到本地目录
参数:
local_path: 本地路径
remote_path: 远程路径
"""
print("download_file_tree()---> local_path = %s ,remote_path = %s" % (local_path, remote_path))
try:
self.ftp.cwd(remote_path)
except Exception as err:
self.debug_print('远程目录%s不存在,继续...' % remote_path + " ,具体错误描述为:%s" % err)
return
if not os.path.isdir(local_path):
self.debug_print('本地目录%s不存在,先创建本地目录' % local_path)
os.makedirs(local_path)
self.debug_print('切换至目录: %s' % self.ftp.pwd())
self.file_list = []
# 方法回调
self.ftp.dir(self.get_file_list)
remote_names = self.file_list
self.debug_print('远程目录 列表: %s' % remote_names)
for item in remote_names:
file_type = item[0]
file_name = item[1]
local = os.path.join(local_path, file_name)
if file_type == 'd':
print("download_file_tree()---> 下载目录: %s" % file_name)
self.download_file_tree(local, file_name)
elif file_type == '-':
print("download_file()---> 下载文件: %s" % file_name)
self.download_file(local, file_name)
self.ftp.cwd("..")
self.debug_print('返回上层目录 %s' % self.ftp.pwd())
return True
def upload_file(self, local_file, remote_file):
"""从本地上传文件到ftp
......
......@@ -8,7 +8,7 @@ import pandas as pd
import numpy as np
import re
from wanjia_tuomin.micko import modifyStatus, constants, DbUtils
from wanjia_tuomin.data_process import modifyStatus, constants, DbUtils
import time
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment