-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftp-to-picasaweb-bridge.py
72 lines (57 loc) · 2 KB
/
ftp-to-picasaweb-bridge.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
71
import base64
import hashlib
import os
import pyftpdlib.handlers
import pyftpdlib.servers
import picasaweb
import requests
import tempfile
class MyHandler(pyftpdlib.handlers.FTPHandler):
def on_connect(self):
print "%s:%s connected" % (self.remote_ip, self.remote_port)
def on_disconnect(self):
# do something when client disconnects
pass
def on_login(self, username):
# do something when user login
pass
def on_logout(self, username):
# do something when user logs out
pass
def on_file_sent(self, file):
# do something when a file has been sent
pass
def on_file_received(self, file):
# do something when a file has been received
print "Recieved file: %s" % file
picasaweb.upload_photo(file)
os.remove(file)
pass
def on_incomplete_file_sent(self, file):
# do something when a file is partially sent
pass
def on_incomplete_file_received(self, file):
# remove partially uploaded files
print "Incomplete file: %s" % file
os.remove(file)
class DummyHashAuthorizer(pyftpdlib.handlers.DummyAuthorizer):
def validate_authentication(self, username, password, handler):
hashed_password = base64.b64encode(hashlib.sha512(password).digest())
return self.user_table[username]['pwd'] == hashed_password
temp_dir = tempfile.mkdtemp()
print "Temp directory: %s" % temp_dir
authorizer = DummyHashAuthorizer()
authorizer.add_user(
'btsai', '0LLO0HtbyAoXnFtIEbDol+ZsL/zi91ZlMNse0RtiMsLI36HX8nNdrGtwK07yW6bFee2/VP/hQr+K6JW/xuP+Vw==',
homedir=temp_dir,
perm='elradfmw')
# authorizer.add_anonymous(homedir='.')
import logging
import pyftpdlib.log
pyftpdlib.log.LEVEL = logging.DEBUG
handler = MyHandler
handler.authorizer = authorizer
handler.passive_ports = list(xrange(2122, 2221))
handler.masquerade_address = requests.get('https://api.ipify.org').text
server = pyftpdlib.servers.FTPServer(('', 2121), handler)
server.serve_forever()