One line ftp server in python

前端 未结 9 1809
清歌不尽
清歌不尽 2020-12-07 08:03

Is it possible to have a one line command in python to do a simple ftp server? I\'d like to be able to do this as quick and temporary way to transfer files to a linux box wi

相关标签:
9条回答
  • 2020-12-07 08:07
    apt-get install python3-pip
    
    pip3 install pyftpdlib
    
    python3 -m pyftpdlib -p 21 -w --user=username --password=password
    
    -w = write permission
    
    -p = desired port
    
    --user = give your username
    
    --password = give your password
    
    0 讨论(0)
  • 2020-12-07 08:08

    For pyftpdlib users. I found this on the pyftpdlib website. This creates anonymous ftp with write access to your filesystem so please use with due care. More features are available under the hood for better security so just go look:

    sudo pip3 install pyftpdlib
    
    python3 -m pyftpdlib -w  
    
    ## updated for python3 Feb14:2020
    

    Might be helpful for those that tried using the deprecated method above.

    sudo python -m pyftpdlib.ftpserver

    0 讨论(0)
  • 2020-12-07 08:11

    I dont know about a one-line FTP server, but if you do

    python -m SimpleHTTPServer
    

    It'll run an HTTP server on 0.0.0.0:8000, serving files out of the current directory. If you're looking for a way to quickly get files off a linux box with a web browser, you cant beat it.

    0 讨论(0)
  • 2020-12-07 08:13

    The simpler solution will be to user pyftpd library. This library allows you to spin Python FTP server in one line. It doesn’t come installed by default though, but we can install it using simple apt command

    apt-get install python-pyftpdlib
    

    now from the directory you want to serve just run the pythod module

    python -m pyftpdlib -p 21 
    
    0 讨论(0)
  • 2020-12-07 08:18

    Install:

    pip install twisted
    

    Then the code:

    from twisted.protocols.ftp import FTPFactory, FTPRealm
    from twisted.cred.portal import Portal
    from twisted.cred.checkers import AllowAnonymousAccess, FilePasswordDB
    from twisted.internet import reactor
    
    reactor.listenTCP(21, FTPFactory(Portal(FTPRealm('./'), [AllowAnonymousAccess()])))
    reactor.run()
    

    Get deeper:

    http://twistedmatrix.com/documents/current/core/examples/

    0 讨论(0)
  • 2020-12-07 08:20

    Check out pyftpdlib from Giampaolo Rodola. It is one of the very best ftp servers out there for python. It's used in google's chromium (their browser) and bazaar (a version control system). It is the most complete implementation on Python for RFC-959 (aka: FTP server implementation spec).

    From the commandline:

    python -m pyftpdlib
    

    Alternatively 'my_server.py':

    #!/usr/bin/env python
    
    from pyftpdlib import servers
    from pyftpdlib.handlers import FTPHandler
    address = ("0.0.0.0", 21)  # listen on every IP on my machine on port 21
    server = servers.FTPServer(address, FTPHandler)
    server.serve_forever()
    

    There's more examples on the website if you want something more complicated.

    To get a list of command line options:

    python -m pyftpdlib --help
    

    Note, if you want to override or use a standard ftp port, you'll need admin privileges (e.g. sudo).

    0 讨论(0)
提交回复
热议问题