Python Forum

Full Version: Unable to upload file using FTP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I have a stange problem
I'm using this simple code:
ftp = FTP('10.0.0.1', timeout=60)
    try:
        ftp.login(user='user', passwd='pass')
    except error_perm as msg:
        print(f"FTP error: {msg}")
       # return "Wrong User or Password"
    except Exception as e1:
        print(e1)
        print("Error in FTP Login!")
       # return "Unknown Error"
    else:
        try:
            file_to_upload = open(filename, 'rb')
            ftp.storbinary('STOR test.txt', file_to_upload)
            UploadOk = "OK"
            return "FTP success"
        except Exception as e:
            print('my error')
            print(e)
            UploadOk = "Problem"
            return "FTP Error " + str(e)
        finally:
            print("status " + UploadOk)
            file_to_upload.close()
            ftp.close()
I can see a FTP session is made , but the file won't uplaod
O get this error:
FTP Error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
when I ty to upload to another device (the same file, same code) everything is working - so I know the code\file is OK
the file is test.txt size 1 kb , there is more then 100MB free in the remote device

what could be the reason for the error? why the file isn't been upload ?
Do you have access to the server? Can you check the logs for the FTP server running on there?
it's a home router
no so much logs
all I can see it
Dec/23/2021 14:29:35 user user logged in from 10.0.0.254 via ftp
Dec/23/2021 14:29:57 user user logged out from 10.0.0.254 via ftp
but I have found the problem
it seem that only Port 22 TCP is open , so the connection was made but a port to transer the data is block

when I remove this rule - it works