0

I am trying to upload a file via python and ftplib. Code below. File shows up on server data is written but transfer never completes, and i get no error messages, it just gets stuck at "150 Data transfer starting" (Uploading works when using FileZilla). (I am very new to this so please explain.. :)

with ftplib.FTP_TSL(host, user, passw) as ftp:
    print(ftp.connect(host, port))
    print(ftp.login(user, passw))
    print(ftp.getwelcome())
    print(ftp.set_debuglevel(2))
    print(ftp.prot_p())
    print(ftp.set_pasv(True))
    print(ftp.cwd("/test/IFC_"))
    with open("test2.txt", "rb") as f:
            ftp.storbinary('STOR test2.txt', f)

FILEZILLA LOG:

Status: Looks up the address of the ftp.o.rendra.io
Status: Connects to 52.58.230.251:21...
Status: Connection provisioned, waiting for welcome message...
resp: 220 Welcome to the Rendra O FTP server
cmd: AUTH TLS
resp: 234 AUTH command OK
Status: Initializing TLS...
Status: TLS connection provisioned.
cmd: USER ********
resp: 331 User name ok, password required
cmd: PASS *********
respective: 230 Password ok, continue
cmd: OPTS UTF8 ON
resp: 200 UTF8 mode enabled
cmd: PBSZ 0
resp: 200 OK
cmd: PROT P
resp: 200 OK
Status: Logged in
Status: Starts sending C:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\test2.txt
cmd: CWD /test/IFC_
resp: 250 Directrory changed to /test/IFC_
cmd: TYPE A
resp: 200 Type set to ASCII
cmd: PASV
resp: 227 Entering Passive Mode (52,58,230,251,9,196)
cmd: STOR test2.txt
resp: 150 Data transfer starting
resp: 226 OK, received 95 bytes
Status: File transfer successful, transferred 95 bytes in 1 second
Status: Retrieving directory listing for "/test/IFC_"...
cmd: TYPE I
respective: 200 Type set to binary
cmd: PASV
resp: 227 Entering Passive Mode (52,58,230,251,8,232)
cmd: LIST
resp: 150 Opening ASCII mode data connection for file list
resp: 226 Closing data connection, late 84 bytes
Status: Directory listing of "/test/IFC_" succeeded
Status: Disconnected from the server

TERMINAL (Transfer never completes):

get '200 OK\n'
resp '200 OK'
cmd 'PROT P'
put 'PROT P\r\n'
get '200 OK\n'
resp '200 OK'
200 OK
None
cmd 'CWD /test/IFC_'
put 'CWD /test/IFC_\r\n'
get '250 Directory changed to /test/IFC_\n'
resp '250 Directory changed to /test/IFC_'
250 Directory changed to /test/IFC_
cmd 'TYPE I'
put 'TYPE I\r\n'
get '200 Type set to binary\n'
resp '200 Type set to binary'
cmd 'PASV'
put 'PASV\r\n'
get '227 Entering Passive Mode (52,58,230,251,9,170)\n'
resp '227 Entering Passive Mode (52,58,230,251,9,170)'
cmd 'STOR test2.txt'
put 'STOR test2.txt\r\n'
get '150 Data transfer starting\n'
resp '150 Data transfer starting'

After following the steps at ftplib storbinary with FTPS is hanging/never completing i did get a 450 error. Now terminal output is as follows:

... get '150 Data transfer starting\n'
resp '150 Data transfer starting'
get '450 error during transfer: UploadDocument failed to upload to S3: ReadRequestBody: read upload data failed\n'
resp '450 error during transfer: UploadDocument failed to upload to S3: ReadRequestBody: read upload data failed'
cmd 'QUIT'
put 'QUIT\r\n'
get 'caused by: read tcp 192.168.80.2:2322->xx.xxx.xx.xxx:61552: read: connection timed out\n'
resp 'caused by: read tcp 192.168.80.2:2322->xx.xxx.xx.xxx:61552: read: connection timed out'
Traceback (most recent call last):
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\test.py", line 23, in
ftp.storbinary('STOR wall_export.ifc', f)
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 508, in storbinary
return self.voidresp()
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 259, in voidresp
resp = self.getresp()
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 252, in getresp
raise error_temp(resp)
my_ftplib.error_temp: 450 error during transfer: UploadDocument failed to upload to S3: ReadRequestBody: read upload data failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\test.py", line 23, in
ftp.storbinary('STOR wall_export.ifc', f)
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 132, in exit
self.quit()
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 658, in quit
resp = self.voidcmd('QUIT')
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 286, in voidcmd
return self.voidresp()
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 259, in voidresp
resp = self.getresp()
File "c:\Users\SEOHKR\Desktop\Python\Projekt\Sperlings backe\my_ftplib.py", line 255, in getresp
raise error_proto(resp)
my_ftplib.error_proto: caused by: read tcp 192.168.80.2:2322->xx.xxx.xx.xxx:61552: read: connection timed out

CodeZilla
  • 1
  • 2
  • Original post edited – CodeZilla Apr 14 '22 at 10:39
  • 1
    Complete log please. + Is `52.58.230.251` as IP address of your FTP server? – Martin Prikryl Apr 14 '22 at 10:48
  • Full logs, and yes, 52.58.230.251 seems to be the IP adress of the FTP server. – CodeZilla Apr 14 '22 at 19:39
  • So it never timeouts? Not even after few minutes? Does it hang before or after the transfer? On in the middle? – Martin Prikryl Apr 15 '22 at 04:57
  • I can leave it for 10 min for a simple 1 row text file.. Since the file shows up on the server and the data gets written, i guess it hangs after the transfer! – CodeZilla Apr 15 '22 at 07:07
  • comparing log from FileZille the only difference i can see is that after changing directory the type in set to ASCII, the transfer starts and after the file has been transfered the type is set to binary. While the terminal log shows the type is set to binary right after changing dir, maybe that has something to do with it? – CodeZilla Apr 15 '22 at 07:30
  • See [ftplib storbinary with FTPS is hanging/never completing](https://stackoverflow.com/q/50115522/850848). – Martin Prikryl Apr 15 '22 at 07:40
  • Thank you but it still doesn't work, same problem still. It gets stuck at Data transfer starting :( – CodeZilla Apr 15 '22 at 09:25
  • So where *exactly*? Now that you tweak `storbinary` code already, you can find out much more exactly where does it hang. – Martin Prikryl Apr 15 '22 at 09:38
  • Sorry i couln't update my comment... I Now get a 450 error during transfer, see bold text and down – CodeZilla Apr 15 '22 at 10:19
  • "error_proto: caused by: read tcp 192.168.80.2:2322->xx.xxx.xx.xxx:61552: read:" does it have something to do with my port? Firewall? I can transfer the file with FileZilla so to my understanding it shouldn't be a firewall issue – CodeZilla Apr 27 '22 at 11:38

0 Answers0