RevCurtisP / gedit-ftp-browser

Automatically exported from code.google.com/p/gedit-ftp-browser
0 stars 0 forks source link

Can't do active mode FTP (have included patch to fix issue + minor error message bugs) #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. try to ftp to a site that only accepts active connections

What is the expected output? What do you see instead?
Expect to connect if active mode selected, but don't even have the option.
 Connecting to an active only site with passive mode results in a hang.

What version of the product are you using? On what operating system?
Version 4.0??  Ubuntu 8.04

Please provide any additional information below.

Here is a patch for application to V4.0 which include a button to select
between active and passive mode.  Active / Passive settings persist between
gedit invocations.  The patched plugin appends a line to lastftp.ini, so
that it's backwards compatible with any old lastftp.ini file.  If creation
is required, it also creates lastftp.ini with "600" permissions for
security reasons, as the file may contain a sensitive  password.  Change
also fixes minor bugs in a couple of error messages (which use commas where
they require "+").

The Diff:
=========
diff -uN gedit-ftp-browser-read-only/FTP.py gedit-ftp-browser-V4.1/FTP.py
--- gedit-ftp-browser-read-only/FTP.py  2009-03-23 13:37:38.000000000 +0000
+++ gedit-ftp-browser-V4.1/FTP.py   2009-04-12 02:51:37.000000000 +0100
@@ -26,23 +26,27 @@
 import re
 import sys
 import os
+import subprocess
+

 class FTPWindowHelper:
    def __init__(self, plugin, window):
        self._window = window
        self._plugin = plugin
+       
        # Prime the statusbar
        self.statusbar = window.get_statusbar()
        self.context_id = self.statusbar.get_context_id("FTPPlugin")
        self.message_id = None
        self.config_path = os.path.expanduser('~/.gnome2/gedit/plugins')
        self.ftp_cwd = '/'
-
+       
        # create panel
        self._browser = FileBrowser(self)
        panel = self._window.get_side_panel()
        panel.add_item(self._browser, "FTP Browser", 'gtk-disconnect')
-
+       
+       #load config from file (if it exists)
        self.load_config()

    def flush_events(self):
@@ -54,7 +58,7 @@
        try:
            f = open(self.config_path+"/lastftp.ini");
        except:
-           #print "no config at ",self.config_path+"/lastftp.ini"
+           #if no config file, then silently quit
            pass
        else:
            self._browser.url.set_text(f.readline().strip())
@@ -63,6 +67,10 @@
            self._browser.filt.set_text(f.readline().strip())
            self.ftp_cwd = f.readline().strip()
            self._browser.location.set_text(self.ftp_cwd)
+           if ("True" == f.readline().strip() ):
+               self._browser.combo_pasv_mode.set_active(True)
+           else:
+               self._browser.combo_pasv_mode.set_active(False)
            f.close()

    def save_config(self):
@@ -74,8 +82,10 @@
                return
        try:
            f = open(self.config_path+"/lastftp.ini", "wt");
+           #set '600' permissions as there's password data in the file
+           subprocess.call(["chmod", "600", self.config_path + "/lastftp.ini"])
        except:
-           self.error_msg("Can't write config at ",self.config_path+"/lastftp.ini")
+           self.error_msg("Can't write config at " + self.config_path +
"/lastftp.ini")
            pass
        else:
            f.write(self._browser.url.get_text()+"\n")
@@ -83,6 +93,10 @@
            f.write(self._browser.pasw.get_text()+"\n")
            f.write(self._browser.filt.get_text()+"\n")
            f.write(self.ftp_cwd+"\n")
+           if (self._browser.combo_pasv_mode.get_active()):
+               f.write("True\n")
+           else:
+               f.write("False\n")
            f.close()

    # Statusbar message
@@ -175,6 +189,8 @@
            ftp = FTP()
            ftp.connect(url,port)
            ftp.login(u,p)
+           ftp.set_pasv(self._browser.combo_pasv_mode.get_active())
+
        except:
            self.error_msg('FTP Connecting error')
            return None
@@ -262,6 +278,7 @@
        ff.attach(gtk.Label('Host'),0,1,0,1,False,False);
        ff.attach(gtk.Label('User'),0,1,1,2,False,False);
        ff.attach(gtk.Label('Pass'),0,1,2,3,False,False);
+
        #ff.attach(gtk.Label('Filter'),0,1,3,4,False,False);
        self.url = gtk.Entry()
        self.url.set_size_request(10,-1)
@@ -269,9 +286,9 @@
        self.user.set_size_request(10,-1)
        self.pasw = gtk.Entry()
        self.pasw.set_size_request(10,-1)
+       self.pasw.set_visibility(False)
        self.filt = gtk.Entry()
        self.filt.set_size_request(10,-1)
-       self.pasw.set_visibility(False)

        ff.attach(self.url,1,2,0,1);
        ff.attach(self.user,1,2,1,2);
@@ -299,13 +316,28 @@
        btn_refresh.add(i)
        btn_refresh.connect("clicked", helper.on_refresh)

-
-       buttons=gtk.HBox(False)
-       buttons.pack_start(btn_connect,False,False)
-       buttons.pack_start(btn_refresh,False,False)
-
-       self.pack_start(buttons,False,False)
-
+       #list for combo box (Active/Passive FTP)
+       self.list = gtk.ListStore(int, str)
+       iter = self.list.append( (False, "Active FTP",) )
+       self.list.set(iter)
+       iter = self.list.append( (True, "Passive FTP",) )
+       self.list.set(iter)
+
+       #Combo box
+       self.combo_pasv_mode = gtk.ComboBox()
+       cell = gtk.CellRendererText()
+       self.combo_pasv_mode.pack_start(cell, True)
+       self.combo_pasv_mode.add_attribute(cell, 'text', 1)
+       self.combo_pasv_mode.set_model(self.list)
+       self.combo_pasv_mode.set_active(True) #default: passive mode=True
+       
+       #pack buttons and combo box (active/passive FTP) on same row
+       buttonsAndCombo=gtk.HBox(False)
+       buttonsAndCombo.pack_start(btn_connect,False,False)
+       buttonsAndCombo.pack_start(btn_refresh,False,False)
+       buttonsAndCombo.pack_start(self.combo_pasv_mode,False,False)
+       self.pack_start(buttonsAndCombo,False,False)
+       
        #location label
        self.location = gtk.Label(helper.ftp_cwd)
        self.location.set_line_wrap(True)
Common subdirectories: gedit-ftp-browser-read-only/.svn and
gedit-ftp-browser-V4.1/.svn

Original issue reported on code.google.com by Robin.Ma...@gmail.com on 12 Apr 2009 at 1:53

GoogleCodeExporter commented 9 years ago
tyvm works like a charm

Original comment by hv1...@gmail.com on 3 Oct 2009 at 12:42

GoogleCodeExporter commented 9 years ago
tq will merge it

Original comment by yin...@gmail.com on 3 Nov 2009 at 12:12

GoogleCodeExporter commented 9 years ago

Original comment by yin...@gmail.com on 3 Nov 2009 at 12:47

GoogleCodeExporter commented 9 years ago
hv1989 - thanks - appreciate the feedback

yinsee - thanks for incorporating (most of) my patch.  However I noticed you 
haven't 
included the code to set 600 permissions for lastftp.ini, or the save_config() 
exception error message fix - line 84 in your new code (when I saw this 
exception in 
testing the original code failed to display the error).  I suspect you can 
reproduce 
by making lastftp.ini readonly and changing a setting before shutting down 
gedit.

The completed code doesn't work for me either.  When attempting to connect I 
now get 
the error "FTP LIST error. Reason: <type 'exceptions.NameError'> global name 
'e' is 
not defined"  Lines 298 and 300 look suspect thanks to their use of a[2] and 
"e" 
rather than the previous a[0] and a[8] but as I'm no python expert I'll defer 
to you.

Original comment by Robin.Ma...@gmail.com on 3 Nov 2009 at 2:05