Set up an FTP server that can be created and destroyed immediately (in Python)

There was a convenient FTP server library called pyftpdlib in python, so I tried using it.

Install pyftpdlib

It seems that you can download it from pyftpdlib site ... It is recommended to use pip because it can be installed with one command.

pip install pyftpdlib

By the way, you can use PyCharm to execute pip using GUI! (Promotion) rapture_20140323171404.png

Make a simple FTP server

The basics are as in Quick Start of Official Site.

I did it in a Windows environment, but I think it can be done with other OS

# -*- coding: utf8 -*-
import pyftpdlib.authorizers
import pyftpdlib.handlers
import pyftpdlib.servers

#Create an authenticated user
authorizer = pyftpdlib.authorizers.DummyAuthorizer()
authorizer.add_user('user', 'password', 'C:\\Users\\username\\Pictures', perm='elradfmw')

#Create a handler to manage individual connections
handler = pyftpdlib.handlers.FTPHandler
handler.authorizer = authorizer

#Launch an FTP server
server = pyftpdlib.servers.FTPServer(("127.0.0.1", 21), handler)
server.serve_forever()

In this example, an FTP server with C: \ Users \ username \ Pictures as the root directory will be launched.

Username: user, password: password You can log in with.

As a test, when I connected it with WinSCP, the contents of the image folder were displayed properly.

Various other extensions

I haven't seen it yet, but it seems that there are various examples in Tutorial on the official website.

Recommended Posts

Set up an FTP server that can be created and destroyed immediately (in Python)
Set up a simple HTTPS server in Python 3
Set up a test SMTP server in Python.
Set up a simple SMTP server in Python
Geographic information visualization of R and Python that can be expressed in Power BI
Created an HTTP proxy that can record and play HTTP responses
Scripts that can be used when using bottle in Python
Write an HTTP / 2 server in Python
I bought and analyzed the year-end jumbo lottery with Python that can be executed in Colaboratory
Python standard input summary that can be used in competition pro
I wrote a tri-tree that can be used for high-speed dictionary implementation in D language and Python.
Set up a dummy SMTP server in Python and check the operation of sending from Action Mailer
There are no “private” instance variables in Python that can only be accessed from within an object.
I created a template for a Python project that can be used universally
Deploy and use the prediction model created in Python on SQL Server
Set up a local web server in 30 seconds using python 3's http.server
[Python3] Code that can be used when you want to cut out an image in a specific size
I want to create a priority queue that can be updated in Python (2.7)
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
Easy program installer and automatic program updater that can be used in any language
I made a familiar function that can be used in statistics with Python
Building an environment that uses Python in Eclipse
Building Sphinx that can be written in Markdown
Set up a UDP server in C language
Let's make an app that can search similar images with Python and Flask Part1
Let's make an app that can search similar images with Python and Flask Part2
Summary of statistical data analysis methods using Python that can be used in business
Created a Python library to write complex comprehensions and reduce in an easy-to-read manner
Morphological analysis and tfidf (with test code) that can be done in about 1 minute
Notes on how to use StatsModels that can use linear regression and GLM in python
In Python3.8 and later, the inverse mod can be calculated with the built-in function pow.
A note that runs an external program in Python and parses the resulting line
A mechanism to call a Ruby method from Python that can be done in 200 lines
Basic algorithms that can be used in competition pros
Japanese can be used with Python in Docker environment
Color list that can be set with tkinter (memorial)
Python knowledge notes that can be used with AtCoder
ANTs image registration that can be used in 5 minutes
Set up a free server on AWS in 30 minutes
Can be used in competition pros! Python standard library
Non-linear simultaneous equations can be easily solved in Python.
[Vagrant] Set up a simple API server with python
Set up python and machine learning libraries on Ubuntu
When it is troublesome to set up an SMTP server locally when sending mail with Python.
How to start a simple WEB server that can execute cgi of php and python
Qt-based library "Poppler" that can quickly read PDF as an image in C ++ or Python
Install Mecab and CaboCha on ubuntu16.04LTS so that it can be used from python3 series
[Django] Field names, user registration, and login methods that can be used in the User model
[Python3] Code that can be used when you want to resize images in folder units
[Python] A program to find the number of apples and oranges that can be harvested