This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobftp.py
70 lines (49 loc) · 2.04 KB
/
mobftp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# http://code.google.com/p/pyftpdlib/wiki/Tutorial#4.0_-_Customizing_your_FTP_server
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import sys
import argparse
import logging
"""
FTP server accessing the Mobyle datasets owned or accessible by a user.
For the moment it manages only single/simple datasets (not a datasets containing other ones, like a blastdb or a dir with files)
It also takes all datasets, not just the user ones.
FTP PUT and DELETE are not implemented yet, only GET
"""
def main():
parser = argparse.ArgumentParser(description='Initialize ftp configuration.')
parser.add_argument('--config')
args = parser.parse_args()
if not args.config:
print "config argument is missing"
sys.exit(2)
from mobyle.common.config import Config
mobyle_config = Config(args.config).config()
from mobyle.data.ftp.mobyleauthorizer import MobyleAuthorizer
from mobyle.data.ftp.mobylefilesystem import MobyleFileSystem
from mobyle.common.users import User
from mobyle.common.project import Project
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = MobyleAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
handler.abstracted_fs = MobyleFileSystem
# Define a customized banner (string returned when client connects)
handler.banner = "Mobyle ftp server."
# 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 = '151.25.42.11'
#handler.passive_ports = range(60000, 65535)
# 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()