You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Writing to FTP fails with error "503 ASCII (Text) data type is not supported for file transfer operations. Please configure your FTP client to use IMAGE (Binary) type and try again"
#780
Closed
beck3905 opened this issue
Aug 30, 2023
· 1 comment
· Fixed by #781
I looked at the source code for both smart_open.ftp and the ftplib module in Python and noticed something in the storbinary method that isn't used in smart_open.ftp.open.
The following is the implementation of ftplib.FTP.storbinary:
self.voidcmd('TYPE I')
with self.transfercmd(cmd, rest) as conn:
while 1:
buf = fp.read(blocksize)
if not buf:
break
conn.sendall(buf)
if callback:
callback(buf)
# shutdown ssl layer
if _SSLSocket is not None and isinstance(conn, _SSLSocket):
conn.unwrap()
return self.voidresp()
Notice the self.voidcmd('TYPE I') before calling self.transfercmd.
Problem description
I am trying to write to FTP using smart_open. However, when I do I receive an error that states"
I get the above error regardless of whether I use mode
"w"
or"wb"
.I also noticed in the source code https://github.com/RaRe-Technologies/smart_open/blob/develop/smart_open/ftp.py#L102 that the default mode is
"r"
even though the docstring states that the mode must be"rb"
or"wb"
.Steps/code to reproduce the problem
Tracback
Versions
Please provide the output of:
Possible Solution
I looked at the source code for both smart_open.ftp and the ftplib module in Python and noticed something in the
storbinary
method that isn't used insmart_open.ftp.open
.The following is the implementation of
ftplib.FTP.storbinary
:Notice the
self.voidcmd('TYPE I')
before callingself.transfercmd
.smart_open does not use the
TYPE I
command. https://github.com/RaRe-Technologies/smart_open/blob/develop/smart_open/ftp.py#L149.I ran a test where I updated my local
smart_open.ftp.py
module on line 149 toand it successfully wrote to my FTP server.
Would you mind if I submit a PR with this fix and an update of the default mode to
"rb"
instead of"r"
?The text was updated successfully, but these errors were encountered: