/
FtpOperations.py
79 lines (66 loc) · 2.51 KB
/
FtpOperations.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
from Tkinter import *
import os
import ftplib
import FileOperations
#server.login('daemon','xampp')
def connectServer(IP,username,password,serverFileList):
serverFileList.delete(0,END)
try:
server = ftplib.FTP()
server.connect(IP,21)
server.login(username,password)
#server.cwd('/webalizer')
serverFolderList = server.nlst()
for i in serverFolderList:
serverFileList.insert(END,i)
server.close()
except:
errorBox = Tk()
errorMessage = Label(errorBox,text="Connection Error",width=30).pack()
def uploadServer(IP,username,password,serverFileList,directory,selectFile):
server = ftplib.FTP()
server.connect(IP,21)
server.login(username,password)
#server.cwd('/webalizer')
file = open(os.path.expanduser(directory)+"/"+selectFile,'rb')
server.storbinary('STOR '+selectFile,file)
file.close()
server.close()
connectServer(IP,username,password,serverFileList)
def downloadServer(IP,username,password,directory,fileList,serverFileList):
selectFile=serverFileList.get(serverFileList.curselection())
server = ftplib.FTP()
server.connect(IP,21)
server.login(username,password)
#server.cwd('/webalizer')
localfile = open(os.path.expanduser(directory)+"/"+selectFile,'wb')
server.retrbinary('RETR '+ selectFile,localfile.write,1024)
server.close()
localfile.close()
FileOperations.findFiles(directory,fileList)
def deleteServer(IP,username,password,serverFileList):
selectFile=serverFileList.get(serverFileList.curselection())
server = ftplib.FTP()
server.connect(IP,21)
server.login(username,password)
#server.cwd('/webalizer')
server.delete(selectFile)
server.close()
connectServer(IP,username,password,serverFileList)
def inputValue(IP,username,password,serverFileList):
global inputbox
inputbox = Tk()
enterValueLabel = Label(inputbox,text="Enter File New Name").pack()
newNameValue = Entry(inputbox,width=20)
newNameValue.pack()
submitButton = Button(inputbox,text="OK",command=lambda:okButton(IP,username,password,newNameValue.get(),serverFileList),width=10).pack()
def okButton(IP,username,password,str,serverFileList):
selectFile=serverFileList.get(serverFileList.curselection())
server = ftplib.FTP()
server.connect(IP,21)
server.login(username,password)
#server.cwd('/webalizer')
server.rename(selectFile,str)
server.close()
connectServer(IP,username,password,serverFileList)
inputbox.destroy()