I get a weird error while trying to push file to remote ftp server using FTP over SSL/TLS. I found no trace of solution online :/ Please help.
Here's my code:
from ftplib import FTP_TLS
import sys, os
root = "\\home\\user\\test.txt"
dest = "/Destdir"
ftps = FTP_TLS('xxx.xxx.xxx.xxx')
ftps.set_debuglevel(1)
ftps.set_pasv(False)
ftps.connect(port=21, timeout=80)
ftps.login('user', 'pass')
ftps.prot_p()
ftps.ccc()
try:
ftps.cwd(dest)
except Exception as e:
print(e)
try:
file = open('test.txt', 'rb')
ftps.storbinary('STOR test.txt', file)
file.close()
except Exception as e:
print(e)
ftps.close()
And here's the output of the script:
*resp* '220 nas FTP server ready.'
*cmd* 'AUTH TLS'
*resp* '234 AUTH TLS command successful.'
*cmd* 'USER user'
*resp* '331 Password required for user.'
*cmd* 'PASS **********'
*resp* '230 User user logged in.'
*cmd* 'PBSZ 0'
*resp* '200 PBSZ command successful (PBSZ=0).'
*cmd* 'PROT P'
*resp* '200 Protection level set to Private.'
*cmd* 'CCC'
*resp* '200 Clearing control channel protection.'
*cmd* 'CWD /Destdir'
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*resp* '200 Type set to I.'
*cmd* 'PORT 10,10,99,11,220,211'
*resp* '200 PORT command successful.'
*cmd* 'STOR test.txt'
*resp* "150 Opening BINARY mode data connection for 'test.txt'."
_ssl.c:704: The handshake operation timed out
As connection to remote FTP server is fine then I suppose it is not a firewall issue.
Note: Remote FTP server is a Synology NAS, with up to date OS.
EDIT_0:
Another try with passive mode gave that result:
*resp* '220 nas FTP server ready.'
*cmd* 'AUTH TLS'
*resp* '234 AUTH TLS command successful.'
*cmd* 'USER user'
*resp* '331 Password required for user.'
*cmd* 'PASS **********'
*resp* '230 User user logged in.'
*cmd* 'PBSZ 0'
*resp* '200 PBSZ command successful (PBSZ=0).'
*cmd* 'PROT P'
*resp* '200 Protection level set to Private.'
*cmd* 'CCC'
*resp* '200 Clearing control channel protection.'
*cmd* 'CWD /Destdir'
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*resp* '200 Type set to I.'
*cmd* 'PASV'
*resp* '227 Entering Passive Mode (xxx,xxx,xxx,xxx,216,241)'
*cmd* 'STOR test.txt'
*resp* "150 Opening BINARY mode data connection for 'test.txt'."
_ssl.c:704: The handshake operation timed out
I also tried extended passive mode now but it didn't help too:
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*resp* '200 Type set to I.'
*cmd* 'EPSV'
*resp* '229 Entering Extended Passive Mode (|||55536|)'
*cmd* 'STOR test.txt'
*resp* "150 Opening BINARY mode data connection for 'test.txt'."
_ssl.c:704: The handshake operation timed out
EDIT_1: So the script works partially, it's able to open connection, starts transfer of the file. File get's created on the remote server but it doesn't contain the same data as source file. Destination file ends up wih 1KB size and just some random chars (file is ANSII encoded, while source file is UTF8. In the meanwhile I am able to upload a file succesfully using WinSCP.