forked from geraldspreer/the-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makerFtpTools.py
executable file
·130 lines (94 loc) · 3.49 KB
/
makerFtpTools.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
import sys
from ftplib import FTP
import wx
class Browser:
def __init__(self, server, root, user, password):
"""
This class provides essential FTP functions like
ls, isdir, etc. It is intended to be used with makerFtpBrowser
via a controller object.
"""
# set this to True to get a little more information on stdout
self.debug = False
self.root = root
self.log('init ftp browser; logging in...')
self.ftp = FTP(server)
result = self.ftp.login(user, password)
self.ftp.cwd(root)
# ------------------------------------------------------------
def logout(self):
self.log('logging out...')
self.ftp.close()
# ------------------------------------------------------------
def ls(self):
self.log('command : ls')
self.aList = ["this directory is empty..."]
try:
self.aList = self.ftp.nlst()
self.rootlist = self.aList # ITB 14/09/2007 corrected typo missing 's' from self
return self.aList
except:
return self.aList
# ------------------------------------------------------------
def pwd(self):
return self.ftp.pwd()
# ------------------------------------------------------------
def cd(self, aDir):
self.log('switching dir...')
self.ftp.cwd(str(aDir))
# ------------------------------------------------------------
def isdir(self, aDir):
self.log('checking if this is a dir...')
if aDir in ['/', '.']: return True
try:
self.ftp.cwd(str(aDir))
self.ftp.cwd('..')
return True
except:
return False
# ------------------------------------------------------------
def mkd(self, aDir):
self.log('making dir %s' % str(aDir))
try:
self.ftp.mkd(str(aDir))
return True
except Exception, e:
return False
# ------------------------------------------------------------
def deleteFile(self, filePath):
current = self.ftp.pwd()
self.ftp.cwd(self.root)
try:
print "deleting:", filePath
self.ftp.delete(filePath)
self.ftp.cwd(current)
return True
except Exception, e:
self.ftp.cwd(current)
return str(e)
def rmd(self, aDir):
print 'deleting dir %s' % str(aDir)
try:
self.ftp.rmd(str(aDir))
return True
except Exception, e:
print str(e)
return str(e)
# ------------------------------------------------------------
def isfile(self, aPath, aFile):
self.log('checking for file %s' % str(aFile))
#self.ftp.cwd(aPath)
list = self.ftp.nlst()
if aFile in list:
try:
self.ftp.cwd(aFile)
except Exception, e:
self.log('this is a file ' + str(e))
return True
self.ftp.cwd("..")
return False
# ------------------------------------------------------------
def log(self, theText):
if self.debug:
print "makerFtpTools: %s" % str(theText)