# Freeman Lo # # This is a ftp client written in python with Tkinter as the GUI. # Much of this was a pain to do due to the complicated natur of # the GUI toolkit. There are three types of Geometry Manager. I have # selected and used the grid geometry manager instead of the pack # geometry manager or the place geometry. There were pluses and minuses to each of the Geometries. # The Tk toolkit itself is quite old and many people have migrated over # to the wx python GUI toolkit. I found this out too late to work on the wx GUI. # I will try to create this program again over this summer and make it # better and stick a GNU GPL v.2 and post this app on SourceForge.org # for the masses. # Key components to have: linux compatible, diversify complicated methods # Create more functionalities such as printout messages for errors # and allow for all directory path difference and file differences # directories differences and much more functionalities are needed. #################################################################### import ftplib import os, sys, urlparse import re import thread import threading from ftplib import FTP from Tkinter import * # Fuction Area def getServerString(): servername = ent1.get() def getUserName(): username = ent2.get() def getPassword(): password = ent3.get() def exit(): sys.exit() def writeString(mess): text1.insert(INSERT, mess) def clearBox(): ent1.delete(0,128) ent2.delete(0,128) ent3.delete(0,128) def downWithData(stuff): fi.write(stuff) text1.insert(INSERT, "#") print '#', def disconnect(fi, ftp): ftp.quit() fi.close() def setLogin(): serv = ent1.get() if ent2.get() == "" and ent3.get() =="": usrn = "anonymous" pawd = "anonymous" else: usrn = ent2.get() pawd = ent3.get() url = urlparse.urlparse(serv) # url[1] # needs regular expression to get filename # this is re for getting the filename lock = threading.Lock() lock.acquire() exp = re.compile(r'(\w*)\.(\w*)') a = exp.search(url[2]) fin = a.group() # Filename From the URL lock.release() # this is re for getting the URL lock.acquire() exp = re.compile(r'(\w*/)*') a = exp.search(url[2]) path = a.group() # directories from the URL lock.release() # this is getting the local machine path using all kinds of stuff lock.acquire() fn = os.getenv("USERPROFILE")+"\\DESKTOP\\"+fin lock.release() # needs a local file open descriptor lock.acquire() fi = open(fn,'w') lock.release() # it will be awhile before i can get here ftp = FTP(url[1], usrn, pawd) ftp.connect() ftp.login() lock.acquire() mess = ftp.getwelcome() writeString(mess) # thread.start_new_thread(writeString, ()) lock.release() lock.acquire() writeString("\n") mess = ftp.cwd(path) writeString(mess) # thread.start_new_thread(writeString, ()) lock.release() # downWithData(fi) lock.acquire() ftp.retrbinary('RETR '+fin, fi.write) # setAbort(ftp) lock.release() lock.acquire() disconnect(fi, ftp) lock.release() # thread.start_new_thread(disconnect, ()) # fi.close() # ftp.quit() # variables # primary window, main window, size of window root = Tk() root.title("Freeman FTP Client") # size of the screen #root.minsize(250, 250) #root.maxsize(290, 270) # create menus menu = Menu(root) root.config(menu=menu) filemenu = Menu(menu) menu.add_cascade(label="File", menu=filemenu) filemenu.add_command(label="Login", command=setLogin) #filemenu.add_command(label="Abort", command=setAbort) filemenu.add_command(label="Exit", command=exit) #editmenu = Menu(menu) #menu.add_cascade(label="Edit", menu=editmenu) #editmenu.add_command(label="Abort", command=setAbort) #editmenu.add_command(label="die", command=setAbort) #servermenu = Menu(menu) #menu.add_cascade(label="Server") #servermenu.add_command(label="connect...", command=setAbort) #servermenu.add_command(label="disconnect...", command=setAbort) # create labels and entries lab1 = Label(root,text="URL :") lab1.grid(row=0, column=0) ent1 = Entry(root, width=35, takefocus=1, relief=SUNKEN) ent1.grid(row=0, column=1) lab2 = Label(root,text="User Name:") lab2.grid(row=1, column=0) ent2 = Entry(root, width=35, relief=SUNKEN) ent2.grid(row=1, column=1) lab3 = Label(root,text="Password:") lab3.grid(row=2, column=0) ent3 = Entry(root, width=35, show="*", relief=SUNKEN) ent3.grid(row=2, column=1) # create Button but1 = Button(root, width=10, text="Clear All", command=clearBox) but1.grid(row=0, column=2) but2 = Button(root, width=10, text="Exit", command=exit) but2.grid(row=1, column=2) but3 = Button(root, width=10, text="Login", command=setLogin) # getServerString do the command a little later but3.grid(row=2, column=2) # create Text Box text1 = Text(root, bg="#ffffff", relief=SUNKEN, height=15, width=70) text1.grid(row=4, columnspan=5) # create Text Areas to display stuff status = Label(root, text="Status Bar", height=1, width=70, bd=1, relief=SUNKEN, anchor=W) status.grid(row=6, columnspan=5) root.mainloop()