-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_ftp.py
50 lines (44 loc) · 1.55 KB
/
plugin_ftp.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
import logging, os, ftplib, datetime
from urlparse import urlparse
from flexget.entry import Entry
from flexget.plugin import register_plugin
from flexget.utils.cached_input import cached
log = logging.getLogger('ftp')
class InputFtp(object):
def validator(self):
from flexget import validator
root = validator.factory('dict')
root.accept('list', key='dirs').accept('text')
config = root.accept('dict', key='config', required=True)
config.accept('integer', key='use-ssl')
config.accept('text', key='name')
config.accept('text', key='username')
config.accept('text', key='password')
config.accept('text', key='host')
config.accept('integer', key='port')
return root
def on_task_input(self, task, config):
if(config['config']['use-ssl'] == 1):
ftp = ftplib.FTP_TLS()
else:
ftp = ftplib.FTP()
#ftp.set_debuglevel(2)
ftp.connect(config['config']['host'], config['config']['port'])
ftp.login(config['config']['username'], config['config']['password'])
ftp.sendcmd('TYPE I')
ftp.set_pasv(True)
entries = []
for path in config['dirs']:
baseurl = "ftp://%s:%s@%s:%s/" % (config['config']['username'], config['config']['password'], config['config']['host'], config['config']['port'] )
dirs = ftp.nlst(path)
for p in dirs:
url = baseurl + p
title = os.path.basename(p)
#title = title.replace('.', ' ')
entry = Entry()
entry['title'] = title
entry['description'] = title
entry['url'] = url
entries.append(entry)
return entries
register_plugin(InputFtp, 'ftp_list', api_ver=2)