73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
# import debugpy
|
|
# debugpy.listen(3000)
|
|
|
|
# debugpy.wait_for_client()
|
|
|
|
# python3 -m debugpy --wait-for-client --listen 0.0.0.0:3000 ./try.py
|
|
|
|
# {
|
|
# "name": "Attach (Remote Debug)",
|
|
# "type": "python",
|
|
# "request": "attach",
|
|
# "connect": {
|
|
# "host": "localhost", // replace this with remote machine name
|
|
# "port": 3000
|
|
# },
|
|
# "pathMappings": [
|
|
# {
|
|
# "localRoot": "${workspaceFolder}/python-scripts",
|
|
# "remoteRoot": "/home/app"
|
|
# }
|
|
# ]
|
|
# },
|
|
|
|
import os
|
|
|
|
from pyftpdlib.authorizers import DummyAuthorizer
|
|
# from pyftpdlib.handlers import FTPHandler
|
|
from pyftpdlib.handlers import TLS_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
|
|
authorizer.add_user('user', '4s6cP4VRF25eGmQV', '/home/data', perm='elradfmwMT')
|
|
# authorizer.add_anonymous(os.getcwd())
|
|
|
|
# Instantiate FTP handler class
|
|
#handler = FTPHandler
|
|
handler = TLS_FTPHandler
|
|
# handler.keyfile = '/etc/letsencrypt/live/h07.ru/privkey.pem'
|
|
# handler.certfile = '/etc/letsencrypt/live/h07.ru/cert.pem'
|
|
handler.keyfile = '/home/cert/key.pem'
|
|
handler.certfile = '/home/cert/cert.pem'
|
|
handler.authorizer = authorizer
|
|
# requires SSL for both control and data channel
|
|
handler.tls_control_required = True
|
|
handler.tls_data_required = True
|
|
|
|
# Define a customized banner (string returned when client connects)
|
|
handler.banner = "pyftpdlib based ftpd ready."
|
|
|
|
# Specify a masquerade address and the range of ports to use for
|
|
# passive connections. Decomment in case you're behind a NAT.
|
|
handler.masquerade_address = '188.120.235.192'
|
|
handler.passive_ports = range(49153, 49288)
|
|
|
|
# Instantiate FTP server class and listen on 0.0.0.0:2121
|
|
address = ('', 2121)
|
|
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()
|