Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
europa-erp-python
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5d7e1fec
authored
Mar 27, 2025
by
刘豪
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update
parent
0f08e470
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
7 deletions
utils/ftp.py
utils/ftp.py
View file @
5d7e1fec
import
ftplib
import
ftplib
import
os
class
FTPUtil
:
class
FTPUtil
:
...
@@ -20,12 +21,37 @@ class FTPUtil:
...
@@ -20,12 +21,37 @@ class FTPUtil:
def
get_connection
(
self
):
def
get_connection
(
self
):
return
self
.
ftp
return
self
.
ftp
def
download
(
self
,
remote_path
,
local_path
):
def
download
(
self
,
remote_file
,
local_file
):
"""
try
:
remote_path means the remote file name
# 检查本地文件是否已经存在,如果存在则获取其大小
and local_path is the local file name.
local_file_size
=
0
"""
if
os
.
path
.
exists
(
local_file
):
with
open
(
local_path
,
'wb'
)
as
fp
:
local_file_size
=
os
.
path
.
getsize
(
local_file
)
self
.
ftp
.
retrbinary
(
'RETR '
+
remote_path
,
fp
.
write
)
# 设置从指定位置开始下载
self
.
ftp
.
voidcmd
(
'TYPE I'
)
remote_file_size
=
self
.
ftp
.
size
(
remote_file
)
if
local_file_size
<
remote_file_size
:
self
.
ftp
.
sendcmd
(
'REST {}'
.
format
(
local_file_size
))
# 以追加模式打开本地文件
with
open
(
local_file
,
'ab'
)
as
file
:
def
callback
(
data
):
file
.
write
(
data
)
# 开始下载文件
self
.
ftp
.
retrbinary
(
'RETR {}'
.
format
(
remote_file
),
callback
)
print
(
f
'{local_file} 文件下载完成'
)
except
Exception
as
e
:
print
(
f
'下载 {local_file} 过程中出现错误: {e}'
)
# def download(self, remote_path, local_path):
# """
# remote_path means the remote file name
# and local_path is the local file name.
# """
# with open(local_path, 'wb') as fp:
# self.ftp.retrbinary('RETR ' + remote_path, fp.write)
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