我想運行一個簡單的腳本FTPS從Linux中上傳文件計劃的基礎上,以一個實例FTPS在Windows Server 2012上運行時,我嘗試和測試在我的桌面(OS X)的劇本,腳本錯誤出:Python和ftplib的FTP上傳錯誤。
上傳文件時出錯:[錯誤54]通過對等連接復位
如果我運行在Linux中,相同的錯誤的腳本,除了104而不是54:
上傳文件時出錯:由對等[錯誤104]連接復位
我上傳的文件不是空的就是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)