1

I'm trying to connect to an FTP server programmatically. The language of my choice is Python, which is simple enough:

from ftplib import FTP
ftp = FTP(host=FTP_HOST, user=FTP_USERNAME, passwd=FTP_PASSWORD)
ftp.dir()

If I run these three lines on my local machine, it returns a filelist (nlst works as well, as a sidenote). If I now run my Docker container, enter it (docker exec), and go to python, and try to run the same three commands there, it produces a timeout.

I originally suspected it has something to do with the ports, so I exposed port 21, and instructed ftplib to operate over the exposed port, but this gave the same behaviour.

Does anyone have an idea on how to figure out why it works fine locally, but refuses in a container?

EDIT: I'm using passive FTP, and the server is not running on my local machine.

5
  • Possibly active vs passive FTP. Active FTP requires the client (Docker container) to open data ports in addition to 21 so is not practical. Verify using passive FTP in Python.
    – Peleion
    May 5, 2020 at 16:03
  • And where is the target FTP server? Docker will not be able to access ports on the same host by default.
    – Peleion
    May 5, 2020 at 16:06
  • I'm using passive FTP (which appears to be the default in ftplib), and the server is not running on my local machine or even my network.
    – Eggman
    May 5, 2020 at 17:08
  • @Peleion Docker will not be able to access ports on the same host by default. Uh? It's fairly frequent to have several containers talk to each other (docker-compose, Kubernetes pods...)
    – xenoid
    May 5, 2020 at 17:59
  • Absolutely correct and a huge feature but talking to other containers on a Docker network is different from talking to the host ports directly
    – Peleion
    May 5, 2020 at 18:02

2 Answers 2

1

The problem has not been found, but it does appear to be limited to Docker on Windows. The same container works fine on other systems. Under windows, there is communication between the client and the server, and the server responds just fine, but actually transferring files/data results in a timeout.

1

I happened to run into the same issue, I was able to access FTP when executing code in a venv on my dev machine. However it timed out when the same code executes in a docker container on the same machine (Docker desktop for windows). I got it to work by accessing the FTP site via public IP address.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .