Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FTP error "500 Illegal PORT command" while trying to connect from a dockerized Python script

I've created a Python Flask script which moves some file from an FTP server to another when certain condition happens. (both the FTP servers are in two different Docker) On my local machine the script works fine but when I try to put it in a Docker it boot up but when a request arrives I get two errors:

ftplib.error_perm: 500 Illegal PORT command.
ftplib.error_perm: 550 Illegal PORT command. Probably the file is no longer avaible on the FTP server?

Since that from my local machine works well I was thinking that it could be a problem with docker.

This is the code which triggers the copy:

for filename, n in n_request:
    print(self.color + "File name: " + filename + " Count: " + str(n) + RESET, flush=True)
    if n >= int(self.count):
        print(self.color + "Mooving file: " + filename + " from server: " + str(self.server) + RESET, flush=True)
        start = time.time()
        check = move_file(filename, self.server, self.client)
        end = time.time()

And this is the move_file function:

def move_file(filename, server, client):
    from_ftp = FTP_handler(server[0], server[1], DEFAULT_USER, DEFAULT_PSW)
    to_ftp = FTP_handler(client[1], client[2], DEFAULT_USER, DEFAULT_PSW)
    return transfer_file(from_ftp, to_ftp, filename)

The connection is set to be in passive mode.

like image 709
Lorenzo Cavada Avatar asked Oct 24 '25 21:10

Lorenzo Cavada


1 Answers

If you get "500 Illegal PORT command.", you are using the active mode, not the passive mode. Double check that and make sure to really use the passive mode.

For an explanation of the error message (even though in different context), see:
ftp_get: Illegal PORT command.

like image 100
Martin Prikryl Avatar answered Oct 26 '25 11:10

Martin Prikryl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!