Index: main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 31881)
+++ main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 31882)
@@ -127,4 +127,7 @@
 	static public boolean isLocalLibrary = false;
 
+    // for storing the original proxy settings on GLI startup    
+    private static Properties startup_proxy_settings = new Properties();
+    
 	/* TODO: If we're using local GLI, collections are built locally. If we're using client-GLI
 	* and it contains a gs2build folder in it, then localBuild will also be true (if this is not
@@ -161,5 +164,5 @@
 
 	static private URL default_gliserver_url=null;
-
+    
 	public Gatherer(String[] args) 
 	{
@@ -344,4 +347,14 @@
 				open_collection_file_path = null;
 			}
+
+
+			// Before calling setProxy, store anything already present
+			// Downloading happens on the machine where GLI is running from, even with clientgli
+			// For downloading with wget, we use ftp/http(s)_proxy env vars, so check if they're
+			// already set
+			if(System.getenv("http_proxy") != null) System.err.println("http_proxy already set");
+			if(System.getenv("https_proxy") != null) System.err.println("https_proxy already set");
+			if(System.getenv("ftp_proxy") != null) System.err.println("ftp_proxy already set");
+
 			
 			// Finally, we're ready to find out the version of the remote Greenstone server 
@@ -660,5 +673,5 @@
 	}
 
-	
+    
 	/** Returns the correct version of the (local or remote) Greenstone server if init() has already been called. */
 	public static int serverVersionNumber() { 
@@ -1452,31 +1465,10 @@
 	static public void setProxy() {
 		try {// Can throw several exceptions
-			if(Configuration.get("general.use_proxy", true)) {
-			    // These are Java properties, therefore see
-			    // https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
-			    // https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
-			    // https://stackoverflow.com/questions/14243590/proxy-settings-in-java
-
-			    // Not sure what proxyType is. And proxySet ceased to exist since JDK 6 or before
-				System.setProperty("http.proxyType", "4");
-				System.setProperty("http.proxyHost", Configuration.getString("general.HTTP_proxy_host", true));
-				System.setProperty("http.proxyPort", Configuration.getString("general.HTTP_proxy_port", true));
-				//System.setProperty("http.proxySet", "true");
-				
-				System.setProperty("https.proxyHost", Configuration.getString("general.HTTPS_proxy_host", true));
-				System.setProperty("https.proxyPort", Configuration.getString("general.HTTPS_proxy_port", true));
-
-				System.setProperty("ftp.proxyHost", Configuration.getString("general.FTP_proxy_host", true));
-				System.setProperty("ftp.proxyPort", Configuration.getString("general.FTP_proxy_port", true));
-				
-			} else {
-				System.setProperty("http.proxyHost", "");
-				System.setProperty("http.proxyPort", "");
-				//System.setProperty("http.proxySet", "false");
-				System.setProperty("https.proxyHost", "");
-				System.setProperty("https.proxyPort", "");
-				System.setProperty("ftp.proxyHost", "");
-				System.setProperty("ftp.proxyPort", "");
-			}
+		    boolean use_proxy = Configuration.get("general.use_proxy", true);
+		    
+		    setProxyForProtocol("http", use_proxy);
+		    setProxyForProtocol("https", use_proxy);
+		    setProxyForProtocol("ftp", use_proxy);
+			  
 		} catch (Exception error) {
 			DebugStream.println("Error in Gatherer.initProxy(): " + error);
@@ -1485,4 +1477,58 @@
 	}
 
+    private static void setProxyForProtocol(String protocol, boolean use_proxy) throws Exception {
+	// These are Java properties, therefore see
+	// https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
+	// https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
+	// https://stackoverflow.com/questions/14243590/proxy-settings-in-java	
+	
+	if(use_proxy) {
+	    if(System.getenv(protocol+"_proxy") != null) {
+		System.err.println("Overriding original "+protocol+" proxy settings");
+		
+		// first store the original settings, but only if we haven't already stored them for this protocol
+		if(startup_proxy_settings.getProperty(protocol+".proxyHost") == null) {
+		    ///System.err.println("@@@ Overriding with: " + System.getProperty(protocol+".proxyHost", ""));
+		    startup_proxy_settings.setProperty(protocol+".proxyHost", System.getProperty(protocol+".proxyHost", ""));
+		    startup_proxy_settings.setProperty(protocol+".proxyPort", System.getProperty(protocol+".proxyPort", ""));
+
+		    //if(protocol.equals("http")) {
+			//startup_proxy_settings.setProperty(protocol+".proxyType", System.getProperty(protocol+".proxyType", ""));
+			//startup_proxy_settings.setProperty(protocol+".proxySet", System.getProperty(protocol+".proxySet", ""));
+		    //}
+		}
+	    }
+	    
+	    // finally can now set the custom proxy defined through GLI for this protocol
+	    System.setProperty(protocol+".proxyHost", Configuration.getString("general."+protocol.toUpperCase()+"_proxy_host", true));
+	    System.setProperty(protocol+".proxyPort", Configuration.getString("general."+protocol.toUpperCase()+"_proxy_port", true));
+
+	    // Not sure what proxyType is. And proxySet ceased to exist since JDK 6 or before. See links above.
+	    // But we used to set them both for HTTP before, so still doing so for proxyType which may or may not exist
+	    // but proxySet doesn't exist anymore, so not continuing with that.
+	    if(protocol.equals("http")) {
+		System.setProperty(protocol+".proxyType", "4");
+		//System.setProperty(protocol+".proxySet", "true");
+	    }
+	    
+	}
+
+	else { // use_proxy=false, not using proxy defined through GLI, so
+	    // either unset proxy vars for this protocol, or restore any original settings for them
+
+	    if(System.getenv(protocol+"_proxy") != null) {
+		System.err.println("Restoring original "+protocol+" proxy settings");
+		System.setProperty(protocol+".proxyHost", startup_proxy_settings.getProperty(protocol+".proxyHost"));
+		System.setProperty(protocol+".proxyPort", startup_proxy_settings.getProperty(protocol+".proxyPort"));
+
+		//if(protocol.equals("http")) {
+		    //System.setProperty(protocol+".proxyHost", startup_proxy_settings.getProperty(protocol+".proxyType"));
+		    //System.setProperty(protocol+".proxyPort", startup_proxy_settings.getProperty(protocol+".proxySet"));
+		//}
+	    }
+
+	}
+    }
+    
 	
 	/** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has voluntarily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
