-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilezilla2mc-hotlist.py
executable file
·61 lines (49 loc) · 1.68 KB
/
filezilla2mc-hotlist.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
#!/usr/bin/env python
#
# Convert FileZilla sitemanager.xml to Midnight Commander hotlist directory
#
# Usage:
# python ~/bin/filezilla2mc-hotlist.py < ~/.config/filezilla/sitemanager.xml > ~/.config/mc/hotlist
from xml.parsers.expat import ExpatError
from xml.dom import minidom
import sys
def main():
DEFAULT_ENTRY = {
'username': None,
'password': None,
'local_dir': None,
'remote_dir': None,
}
try:
xmldoc = minidom.parse(sys.stdin)
except ExpatError:
print >> sys.stderr, 'Error parsing input file'
sys.exit(1)
entries = {}
for server in xmldoc.getElementsByTagName('Server'):
entry = DEFAULT_ENTRY.copy()
tmp = server.getElementsByTagName('Host')
if not tmp:
continue
hostname = tmp[0].firstChild.nodeValue
tmp = server.getElementsByTagName('RemoteDir')
if tmp and tmp[0].firstChild:
entry['remote_dir'] = tmp[0].firstChild.nodeValue.split()[-1]
if len( entry['remote_dir'] ) < 2:
entry['remote_dir'] = ''
tmp = server.getElementsByTagName('Port')
entry['port'] = tmp[0].firstChild.nodeValue
entries[hostname] = entry
if entries:
for hostname in entries.keys():
entry = entries[hostname]
out = 'ENTRY "'
# protocol = 'ftp://' if entry['port'] == '21' else 'sftp://'
protocol = 'ftp://'
out += protocol + hostname + '" URL "' + protocol + hostname + '/'
if entry['remote_dir']:
out += entry['remote_dir']
out += '"'
print ( out )
if __name__ == '__main__':
main()