-1

okay right now i am using ftp to download a file for my application but the problem is the code as it stands downloads the files when i launch the program and does nothing when i click the download button

# Handlers for MainFrameBase events.
def DownloadButtonClick( ftp,directory,file ):
    ftp.cwd(directory)
    f = open(file,"wb")
    ftp.retrbinary("RETR " + file,f.write)
    f.close()

ftp = ftplib.FTP("ftp.apkmultitool.com")
ftp.login("adkesoapp@apkmultitool.com", "adkesoapp")

DownloadButtonClick(ftp, "", "testfile.txt")

I am using wxbuilder to design the GUI for my application and I am a newbie to python and i have tried Google looking for my answer but nothing has came up I also want when the button is press that it will check for the file and if already exist that it will append to the document instead of overwriting.

i might just scrap the idea and have it download from the raw link of the text file as u doubt i can upload the file back to the server and have it do checks and amend to it as well but i also do not want it to cause duplicated entries so any advice as to prevent that might be best in its own question but this is the bases behind what i am ultimately wanting to accomplish

if you want to see the complete source

https://github.com/ADK-ESO-Project/ADK-ESO-Multi-Tool

raziel23x
  • 71
  • 1
  • 8

1 Answers1

0

Here is a code snippet that creates a GUI with a button. When you click the button you shall notice currently it just prints Clicked in the console. You can place your FTP code there so that when ever you click the button the FTP stuff starts.

Code:

import wx

class Frame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, style=wx.DEFAULT_FRAME_STYLE)
        myPanel = wx.Panel(self,-1)
        myButton = wx.Button(myPanel, -1, 'Download', size=(100,50), pos=(20,20))
        myButton.Bind(wx.EVT_LEFT_DOWN, self.onClick)
        self.Show(True)
    def onClick(self, e):
        print 'Clicked'
        #Put your code here that you
        #want to get executed when ever
        #you click the button.
        #Eg: call your method from here
        #DownloadButtonClick(ftp, "", "testfile.txt")

app = wx.App()
frame = Frame(None, wx.ID_ANY, 'Image')
app.MainLoop()

This is a simple app. You may like to use threading if you want to do more stuff in parallel.

ρss
  • 5,115
  • 8
  • 43
  • 73