]> asedeno.scripts.mit.edu Git - PuTTY_svn.git/blobdiff - psftp.c
Now that Packet structures are dynamically allocated, it means we
[PuTTY_svn.git] / psftp.c
diff --git a/psftp.c b/psftp.c
index 218d363ce79d71d42e7c0359bc18a17ba01c5503..66c59947ae07814f36a9243a28d0f7b2e9745df7 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -1846,6 +1846,15 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
         cfg.port = 22;
     }
 
+    /*
+     * 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.
      */
@@ -1861,7 +1870,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
 
     /* See if host is of the form user@host */
     if (cfg.host[0] != '\0') {
-       char *atsign = strchr(cfg.host, '@');
+       char *atsign = strrchr(cfg.host, '@');
        /* Make sure we're not overflowing the user field */
        if (atsign) {
            if (atsign - cfg.host < sizeof cfg.username) {
@@ -1898,10 +1907,9 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
        cfg.username[sizeof(cfg.username) - 1] = '\0';
     }
     if (!cfg.username[0]) {
-       printf("login as: ");
-       fflush(stdout);
-       if (!fgets(cfg.username, sizeof(cfg.username), stdin)) {
-           fprintf(stderr, "psftp: aborting\n");
+       if (!console_get_line("login as: ",
+                             cfg.username, sizeof(cfg.username), FALSE)) {
+           fprintf(stderr, "psftp: no username, aborting\n");
            cleanup_exit(1);
        } else {
            int len = strlen(cfg.username);
@@ -1913,9 +1921,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,
@@ -2060,6 +2065,15 @@ int psftp_main(int argc, char *argv[])
     argv += i;
     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.