【发布时间】:2015-06-03 19:53:42
【问题描述】:
我正在尝试运行一个简单的 ftps 脚本,以按计划将文件从 Linux 机器上传到在 Windows Server 2012 上运行的 ftps 实例。当我尝试在我的桌面 (OS x) 上测试脚本时,脚本错误:
上传文件时出错:[Errno 54] Connection reset by peer
如果我在 linux 机器上运行脚本,同样的错误,除了 104 而不是 54:
上传文件时出错:[Errno 104] Connection reset by peer
我上传的文件要么是空的,要么是 8 个字节。我已经验证 ftps 正在与我桌面上的其他 2 个客户端一起工作。我错过/忽略了什么?
#!/usr/bin/env python
from ftplib import FTP_TLS
import fnmatch
import os
import ssl
import sys
server = '192.168.1.2'
user = 'myUsername'
passwd = 'myPassword'
def connect_ftp():
ftp = FTP_TLS(server, user, passwd)
ftp.set_pasv(True)
ftp.prot_p()
return ftp
def upload_file(ftp_connection, upload_file_path):
try:
upload_file = open("/tmp/test/" + upload_file_path, 'r')
print('Uploading ' + upload_file_path + "...")
ftp_connection.storbinary('STOR ' + upload_file_path, upload_file)
ftp_connection.quit()
ftp_connection.close()
upload_file.close()
print('Upload finished.')
except Exception, e:
print("Error uploading file: " + str(e))
ftp_conn = connect_ftp()
for file in os.listdir('/tmp/test'):
if fnmatch.fnmatch(file, 'bt_*.txt'):
upload_file(ftp_conn, file)
【问题讨论】: