X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=scp.c;h=ac232fa5ae376f3c6c52c5b7808f469222b750c7;hb=5176e1e9bbdc6620a115da0f92ca2282a6714721;hp=d0f70ae58d246f1dea81e33d3a5126df7950d002;hpb=3c9b8bff57c06dcac47969578539373d04f22eb4;p=PuTTY.git diff --git a/scp.c b/scp.c index d0f70ae5..ac232fa5 100644 --- a/scp.c +++ b/scp.c @@ -1,6 +1,6 @@ /* * scp.c - Scp (Secure Copy) client for PuTTY. - * Joris van Rantwijk, Aug 1999. + * Joris van Rantwijk, Aug 1999, Nov 1999. * * This is mainly based on ssh-1.2.26/scp.c by Timo Rinne & Tatu Ylonen. * They, in turn, used stuff from BSD rcp. @@ -27,6 +27,8 @@ static int recursive = 0; static int preserve = 0; static int targetshouldbedirectory = 0; static int statistics = 1; +static int portnumber = 0; +static char *password = NULL; static int errs = 0; static int connection_open = 0; @@ -70,8 +72,14 @@ static void bump(char *fmt, ...) void ssh_get_password(char *prompt, char *str, int maxlen) { HANDLE hin, hout; - DWORD savemode; - int i; + DWORD savemode, i; + + if (password) { + strncpy(str, password, maxlen); + str[maxlen-1] = '\0'; + password = NULL; + return; + } hin = GetStdHandle(STD_INPUT_HANDLE); hout = GetStdHandle(STD_OUTPUT_HANDLE); @@ -87,7 +95,7 @@ void ssh_get_password(char *prompt, char *str, int maxlen) SetConsoleMode(hin, savemode); - if (i > maxlen) i = maxlen-1; else i = i - 2; + if ((int)i > maxlen) i = maxlen-1; else i = i - 2; str[i] = '\0'; WriteFile(hout, "\r\n", 2, &i, NULL); @@ -112,6 +120,9 @@ static void do_cmd(char *host, char *user, char *cmd) cfg.port = 22; } + if (portnumber) + cfg.port = portnumber; + /* Set username */ if (user != NULL && user[0] != '\0') { strncpy(cfg.username, user, sizeof(cfg.username)-1); @@ -153,7 +164,7 @@ static void print_stats(char *name, unsigned long size, unsigned long done, eta = size - done; else eta = (unsigned long) ((size - done) / ratebs); - sprintf(etastr, "%02d:%02d:%02d", + sprintf(etastr, "%02ld:%02ld:%02ld", eta / 3600, (eta % 3600) / 60, eta % 60); pct = (int) (100.0 * (float) done / size); @@ -266,10 +277,25 @@ static void source(char *src) } if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { - if (recursive) - rsource(src); - else + if (recursive) { + /* + * Avoid . and .. directories. + */ + char *p; + p = strrchr(src, '/'); + if (!p) + p = strrchr(src, '\\'); + if (!p) + p = src; + else + p++; + if (!strcmp(p, ".") || !strcmp(p, "..")) + /* skip . and .. */; + else + rsource(src); + } else { run_err("%s: not a regular file", src); + } return; } @@ -446,7 +472,7 @@ static void sink(char *targ) ssh_send("", 1); return; case 'T': - if (sscanf(buf, "T%d %*d %d %*d", + if (sscanf(buf, "T%ld %*d %ld %*d", &mtime, &atime) == 2) { settime = 1; ssh_send("", 1); @@ -460,7 +486,7 @@ static void sink(char *targ) bump("Protocol error: Expected control record"); } - if (sscanf(buf+1, "%u %u %[^\n]", &mode, &size, namebuf) != 3) + if (sscanf(buf+1, "%u %lu %[^\n]", &mode, &size, namebuf) != 3) bump("Protocol error: Illegal file descriptor format"); if (targisdir) { char t[2048]; @@ -727,9 +753,15 @@ static void usage() { printf("PuTTY Secure Copy client\n"); printf("%s\n", ver); - printf("usage: scp [-p] [-q] [-r] [-v] [user@]host:source target\n"); - printf(" scp [-p] [-q] [-r] [-v] source [source..]" - " [user@]host:target\n"); + printf("Usage: scp [options] [user@]host:source target\n"); + printf(" scp [options] source [source...] [user@]host:target\n"); + printf("Options:\n"); + printf(" -p preserve file attributes\n"); + printf(" -q quiet, don't show statistics\n"); + printf(" -r copy directories recursively\n"); + printf(" -v show verbose messages\n"); + printf(" -P port connect to specified port\n"); + printf(" -pw passw login with specified password\n"); exit(1); } @@ -756,6 +788,10 @@ int main(int argc, char *argv[]) else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0) usage(); + else if (strcmp(argv[i], "-P") == 0 && i+1 < argc) + portnumber = atoi(argv[++i]); + else if (strcmp(argv[i], "-pw") == 0 && i+1 < argc) + password = argv[++i]; else if (strcmp(argv[i], "--") == 0) { i++; break; } else