def ftperror(reason): ''' pops up a dialog informing you of the reason i couldn't upload your file to ftp. ''' d = self.mk_dialog('ftp error', (flauxtext.gtk.STOCK_OK, flauxtext.gtk.RESPONSE_OK)) d.vbox.pack_start(flauxtext.gtk.Label(reason + '\nftp call unsuccessful.')) d.run() self.change_statbar_info(None, " ") def ftp(self_, action=None, ps='', subdirlist=[]): ''' opens a dialog requesting information necessary for me to upload the current file to your ftp space. ''' d = self.mk_dialog('ftp ala flauxtext', (flauxtext.gtk.STOCK_OK, 1, flauxtext.gtk.STOCK_CANCEL,0)) d.connect("delete_event", lambda x,y: d.destroy()) hbxsrv = flauxtext.gtk.HBox() d.vbox.pack_start(hbxsrv) hbxsrv.pack_start(flauxtext.gtk.Label("server")) srvr = flauxtext.gtk.Entry() hbxsrv.pack_start(srvr) srvr.set_text(flauxtext.ftpserver) hbxusr = flauxtext.gtk.HBox() d.vbox.pack_start(hbxusr) hbxusr.pack_start(flauxtext.gtk.Label("handle")) handl = flauxtext.gtk.Entry() hbxusr.pack_start(handl) handl.set_text(flauxtext.ftpname) hbxpw = flauxtext.gtk.HBox() d.vbox.pack_start(hbxpw) hbxpw.pack_start(flauxtext.gtk.Label("pass")) pw = flauxtext.gtk.Entry() pw.connect('activate', lambda pw_: d.response(1)) hbxpw.pack_start(pw) pw.set_visibility(False) pw.set_invisible_char(flauxtext.passchar) pw.set_text(flauxtext.ftppass) hbxdir = flauxtext.gtk.HBox() d.vbox.pack_start(hbxdir) hbxdir.pack_start(flauxtext.gtk.Label("server dir")) dire = flauxtext.gtk.Entry() dire.connect('activate', lambda dire_: d.response(1)) hbxdir.pack_start(dire) dire.set_text("/") dircompl = flauxtext.gtk.EntryCompletion() dire.set_completion(dircompl) dirlist = flauxtext.gtk.ListStore(str) map(dirlist.append, subdirlist) dircompl.set_model(dirlist) dire.grab_focus() if len(flauxtext.ftppass)<2: pw.grab_focus() if len(flauxtext.ftpname)<2: handl.grab_focus() if len(flauxtext.ftpserver)<2: srvr.grab_focus() if d.run(): pw.set_visibility(True) # without this line, i can never get your password to give to ftplib! flauxtext.imp0rt('ftplib') self.change_statbar_info(None, "negotiating with the server...") srv = srvr.get_text() name = handl.get_text() paswd = pw.get_text() if paswd != flauxtext.ftppass: flauxtext.ftppass = paswd srvdir = dire.get_text() if (srv == None) or (name == None) or (srvdir == None) or (len(srv) < 2) or (len(name) < 1) or (len(srvdir) < 1): ftperror('you need to fill out all fields.') return False try: ftp = flauxtext.ftplib.FTP(srv, name, paswd) except flauxtext.ftplib.error_perm: ftperror('invalid login.') return False except: # socket.gaierror ftperror('invalid server specified.') return False fil = open(self.current_filename(), 'rb') try: ftp.cwd(srvdir) except flauxtext.ftplib.error_perm: ftperror('invalid serverside directory specified.') return False result = ftp.storbinary('STOR %s' % flauxtext.os.path.basename(self.current_filename()), fil) ftp.close() self.change_statbar_info(None, " ") d = self.mk_dialog('ftp result', (flauxtext.gtk.STOCK_OK, 1)) d.vbox.pack_start(flauxtext.gtk.Label(result)) d.run()