Malcolm Smith's patch to support CHAP (digest-based) authentication
[u/mdw/putty] / psftp.c
diff --git a/psftp.c b/psftp.c
index 218d363..e5374c5 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -1847,6 +1847,15 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
     }
 
     /*
+     * If saved session / Default Settings says SSH-1 (`1 only' or `1'),
+     * then change it to SSH-2, on the grounds that that's more likely to
+     * work for SFTP. (Can be overridden with `-1' option.)
+     * But if it says `2 only' or `2', respect which.
+     */
+    if (cfg.sshprot != 2 && cfg.sshprot != 3)
+       cfg.sshprot = 2;
+
+    /*
      * Enact command-line overrides.
      */
     cmdline_run_saved(&cfg);
@@ -1913,9 +1922,6 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
     if (portnumber)
        cfg.port = portnumber;
 
-    /* SFTP uses SSH2 by default always */
-    cfg.sshprot = 2;
-
     /*
      * Disable scary things which shouldn't be enabled for simple
      * things like SCP and SFTP: agent forwarding, port forwarding,
@@ -2061,6 +2067,15 @@ int psftp_main(int argc, char *argv[])
     back = NULL;
 
     /*
+     * If the loaded session provides a hostname, and a hostname has not
+     * otherwise been specified, pop it in `userhost' so that
+     * `psftp -load sessname' is sufficient to start a session.
+     */
+    if (!userhost && cfg.host[0] != '\0') {
+       userhost = dupstr(cfg.host);
+    }
+
+    /*
      * If a user@host string has already been provided, connect to
      * it now.
      */