Exemple #1
0
class MicroFTPCore:
    def __init__(self):
        self.debug = 0  # Set to 1 or 2 to enable logging
        self.window = Window(None)
        self.ftp = FTPConnection(self)
        self.view = None
        self.host = ''
        self.notconnected = NotConnectedFrame(parent=self.window, core=self)
        self.ftpbrowser = None

    def console_log(self, msg):
        """Prints a log message to terminal if debug is on

        :param msg: message to log
        """
        if self.debug > 0:
            print datetime.now()
            print msg + "\n"

    def show_ftp_browser(self):
        if self.view != self.ftpbrowser:
            self.ftp.dir()
            self.ftpbrowser = FTPBrowserFrame(parent=self.window, core=self)
            del self.view
            self.view = self.ftpbrowser

    def run(self):
        """Tkinter main loop"""
        self.window.title('MicroFTP')
        self.view = self.notconnected
        self.view.mainloop()

    def connect(self, connection_data):
        """Establish a new FTP connection

        :param connection_data: a dict with keys 'host', 'user' and 'password'
        :return: connection status: 1 if successful, 0 or -1 if an error occured
        """
        connection_status = self.ftp.connect(**connection_data)
        if connection_status == 1:
            self.host = connection_data['host']
        return connection_status

    def disconnect(self):
        """Close the FTP connection and display the connection prompt"""
        self.ftp.disconnect()
        self.view = self.notconnected
        self.view.show_controls()

    def cwd(self, path):
        return self.ftp.cwd(path)
Exemple #2
0
 def __init__(self):
     self.debug = 0  # Set to 1 or 2 to enable logging
     self.window = Window(None)
     self.ftp = FTPConnection(self)
     self.view = None
     self.host = ''
     self.notconnected = NotConnectedFrame(parent=self.window, core=self)
     self.ftpbrowser = None