Create FTP server with Docker Swarm

For MacOS : https://www.python.org/downloads/mac-osx/
For Windows : https://www.python.org/downloads/windows/

I recommend you to use PyCharm community version for the python development, its super easy to use, try this link out

https://www.jetbrains.com/pycharm/download/

https://www.docker.com/get-started

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

def main():
# Instantiate a dummy authorizer for managing ‘virtual’ users
authorizer = DummyAuthorizer()

# Define a new user having full r/w permissions and a read-only
# anonymous user having full r/w permissions and a read-only
authorizer.add_user(‘root’, ‘root’, ‘/file-server/’, perm=’elradfmwMT’)
authorizer.add_anonymous(‘/file-server-anon/’, perm=’elradfmwMT’)

# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Passive ports
handler.passive_ports = range(5000, 5020)
handler.permit_foreign_addresses = True

handler.banner = “pyftpdlib Based FTP Server”

# connect using an address 0.0.0.0 with port 21
address = (”, 21)
server = FTPServer(address, handler)

# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5

# start ftp server
server.serve_forever()

if __name__ == ‘__main__’:
main()

  • file-server
  • file-server-anon

#Docker File for Python FTP Server –Author Waqar Mansoor
FROM python:2.7
RUN pip install pyftpdlib
COPY ./main.py ./
EXPOSE 21
CMD [ “python”, “./main.py” ]

Build the docker image with this command

$ docker build -t ftp-server .

you can see the built image in the list by using this command

$ docker images

version: ‘3.7’

services:
ftp:
image: ftp-server:latest
volumes:
– ../file-server/:/file-server/
– ../file-server-anon/:/file-server-anon/
ports:
– “21:21”
– “5000-5020:5000-5020”

In the above configuration there are two volumes mounted outside the docker container i.e file-server (for normal users), file-server-anon (for anonymous. users)

$ docker stack deploy –compose-file ftp-stack.yml ftp-server-stack

After deploying the stack file you should see these two executed lines indicating the successful deployment of stack file.

Trying to connect as an anonymous user

After successful connection, transfer files in the folder by using the upload option, the directories you have created i.e file-server, file-server-anon earlier will be updated automatically after transfer.

To download all project files please use the link below

You can’t perform that action at this time. You signed in with another tab or window. You signed out in another tab or…

github.com


Leave a Comment

Your email address will not be published. Required fields are marked *