Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wanjia
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kino
wanjia
Commits
84ef6a18
Commit
84ef6a18
authored
Dec 15, 2020
by
宋朋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
47a5a1b2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
84 deletions
+84
-84
MyFTP.py
wanjia_tuomin/data_process/MyFTP.py
+83
-83
file_pretreatment.py
wanjia_tuomin/data_process/file_pretreatment.py
+1
-1
No files found.
wanjia_tuomin/data_process/MyFTP.py
View file @
84ef6a18
...
@@ -52,89 +52,89 @@ class MyFTP:
...
@@ -52,89 +52,89 @@ class MyFTP:
self
.
deal_error
(
"FTP 连接或登录失败 ,错误信息为:
%
s"
%
err
)
self
.
deal_error
(
"FTP 连接或登录失败 ,错误信息为:
%
s"
%
err
)
pass
pass
# def is_same_size(self, local_file, remote_file):
def
is_same_size
(
self
,
local_file
,
remote_file
):
# """判断远程文件和本地文件大小是否一致
"""判断远程文件和本地文件大小是否一致
# 参数:
参数:
# local_file: 本地文件
local_file: 本地文件
# remote_file: 远程文件
remote_file: 远程文件
# """
"""
# try:
try
:
# remote_file_size = self.ftp.size(remote_file)
remote_file_size
=
self
.
ftp
.
size
(
remote_file
)
# except Exception as err:
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):
remote_file_size
=
-
1
# """从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):
try
:
# """从远程目录下载多个文件到本地目录
local_file_size
=
os
.
path
.
getsize
(
local_file
)
# 参数:
except
Exception
as
err
:
# local_path: 本地路径
local_file_size
=
-
1
# remote_path: 远程路径
# """
self
.
debug_print
(
'local_file_size:
%
d , remote_file_size:
%
d'
%
(
local_file_size
,
remote_file_size
))
# print("download_file_tree()---> local_path = %s ,remote_path = %s" % (local_path, remote_path))
if
remote_file_size
==
local_file_size
:
# try:
return
1
# self.ftp.cwd(remote_path)
else
:
# except Exception as err:
return
0
# self.debug_print('远程目录%s不存在,继续...' % remote_path + " ,具体错误描述为:%s" % err)
# return
def
download_file
(
self
,
local_file
,
remote_file
):
#
"""从ftp下载文件
# if not os.path.isdir(local_path):
参数:
# self.debug_print('本地目录%s不存在,先创建本地目录' % local_path)
local_file: 本地文件
# os.makedirs(local_path)
remote_file: 远程文件
#
"""
# self.debug_print('切换至目录: %s' % self.ftp.pwd())
self
.
debug_print
(
"download_file()---> local_path =
%
s ,remote_path =
%
s"
%
(
local_file
,
remote_file
))
#
# self.file_list = []
if
self
.
is_same_size
(
local_file
,
remote_file
):
# # 方法回调
self
.
debug_print
(
'
%
s 文件大小相同,无需下载'
%
local_file
)
# self.ftp.dir(self.get_file_list)
return
#
else
:
# remote_names = self.file_list
try
:
# self.debug_print('远程目录 列表: %s' % remote_names)
self
.
debug_print
(
'>>>>>>>>>>>>下载文件
%
s ... ...'
%
local_file
)
# for item in remote_names:
buf_size
=
1024
# file_type = item[0]
file_handler
=
open
(
local_file
,
'wb'
)
# file_name = item[1]
self
.
ftp
.
retrbinary
(
'RETR
%
s'
%
remote_file
,
file_handler
.
write
,
buf_size
)
# local = os.path.join(local_path, file_name)
file_handler
.
close
()
# if file_type == 'd':
except
Exception
as
err
:
# print("download_file_tree()---> 下载目录: %s" % file_name)
self
.
debug_print
(
'下载文件出错,出现异常:
%
s '
%
err
)
# self.download_file_tree(local, file_name)
return
# elif file_type == '-':
# print("download_file()---> 下载文件: %s" % file_name)
def
download_file_tree
(
self
,
local_path
,
remote_path
):
# self.download_file(local, file_name)
"""从远程目录下载多个文件到本地目录
# self.ftp.cwd("..")
参数:
# self.debug_print('返回上层目录 %s' % self.ftp.pwd())
local_path: 本地路径
# return True
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
):
def
upload_file
(
self
,
local_file
,
remote_file
):
"""从本地上传文件到ftp
"""从本地上传文件到ftp
...
...
wanjia_tuomin/data_process/file_pretreatment.py
View file @
84ef6a18
...
@@ -8,7 +8,7 @@ import pandas as pd
...
@@ -8,7 +8,7 @@ import pandas as pd
import
numpy
as
np
import
numpy
as
np
import
re
import
re
from
wanjia_tuomin.
micko
import
modifyStatus
,
constants
,
DbUtils
from
wanjia_tuomin.
data_process
import
modifyStatus
,
constants
,
DbUtils
import
time
import
time
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment