This commit is contained in:
2025-01-07 18:48:04 +08:00
parent 167418b8c8
commit 6f3a7c2ecc
3 changed files with 10 additions and 13 deletions

10
ftp.py
View File

@ -14,11 +14,10 @@ def set_proxy(proxy_url):
socket.socket = socks.socksocket
print(f"已设置代理: {proxy_host}:{proxy_port}")
def upload_file_to_ftp(server, username, password, file_path, remote_path, proxy_url=None):
def upload_file_to_ftp(server, username, password, file_path, remote_path):
"""上传单个文件到FTP"""
try:
# 设置代理(如果有的话)
set_proxy(proxy_url)
with ftplib.FTP(server) as ftp:
ftp.login(user=username, passwd=password)
@ -40,12 +39,9 @@ def create_remote_directory(ftp, remote_directory):
ftp.cwd(remote_directory) # 再次进入远程目录
print(f"远程目录 {remote_directory} 已创建!")
def upload_directory_to_ftp(server, username, password, local_directory, remote_directory, proxy_url=None):
def upload_directory_to_ftp(server, username, password, local_directory, remote_directory):
"""上传整个目录及其子目录到FTP服务器"""
try:
# 设置代理(如果有的话)
set_proxy(proxy_url)
with ftplib.FTP(server) as ftp:
ftp.login(user=username, passwd=password)