projects
/
u
/
mdw
/
putty
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added a fourth application: plink, a command line connection utility
[u/mdw/putty]
/
scp.c
diff --git
a/scp.c
b/scp.c
index
0bc0f58
..
68eca58
100644
(file)
--- a/
scp.c
+++ b/
scp.c
@@
-1,6
+1,6
@@
/*
* scp.c - Scp (Secure Copy) client for PuTTY.
/*
* scp.c - Scp (Secure Copy) client for PuTTY.
- * Joris van Rantwijk,
Aug 1999, Nov 1999.
+ * Joris van Rantwijk,
Simon Tatham
*
* This is mainly based on ssh-1.2.26/scp.c by Timo Rinne & Tatu Ylonen.
* They, in turn, used stuff from BSD rcp.
*
* This is mainly based on ssh-1.2.26/scp.c by Timo Rinne & Tatu Ylonen.
* They, in turn, used stuff from BSD rcp.
@@
-22,7
+22,7
@@
#define TIME_WIN_TO_POSIX(ft, t) ((t) = (unsigned long) \
((*(LONGLONG*)&(ft)) / (LONGLONG) 10000000 - (LONGLONG) 11644473600))
#define TIME_WIN_TO_POSIX(ft, t) ((t) = (unsigned long) \
((*(LONGLONG*)&(ft)) / (LONGLONG) 10000000 - (LONGLONG) 11644473600))
-int verbose = 0;
+
static
int verbose = 0;
static int recursive = 0;
static int preserve = 0;
static int targetshouldbedirectory = 0;
static int recursive = 0;
static int preserve = 0;
static int targetshouldbedirectory = 0;
@@
-37,6
+37,14
@@
static void rsource(char *src);
static void sink(char *targ);
/*
static void sink(char *targ);
/*
+ * This function is needed to link with ssh.c, but it never gets called.
+ */
+void term_out(void)
+{
+ abort();
+}
+
+/*
* Print an error message and perform a fatal exit.
*/
void fatalbox(char *fmt, ...)
* Print an error message and perform a fatal exit.
*/
void fatalbox(char *fmt, ...)
@@
-63,22
+71,28
@@
static void bump(char *fmt, ...)
va_end(ap);
if (connection_open) {
char ch;
va_end(ap);
if (connection_open) {
char ch;
- ssh_send_eof();
- ssh_recv(&ch, 1);
+ ssh_s
cp_s
end_eof();
+ ssh_
scp_
recv(&ch, 1);
}
exit(1);
}
}
exit(1);
}
-
void ssh_get_password(
char *prompt, char *str, int maxlen)
+
static int get_password(const
char *prompt, char *str, int maxlen)
{
HANDLE hin, hout;
DWORD savemode, i;
if (password) {
{
HANDLE hin, hout;
DWORD savemode, i;
if (password) {
- strncpy(str, password, maxlen);
- str[maxlen-1] = '\0';
- password = NULL;
- return;
+ static int tried_once = 0;
+
+ if (tried_once) {
+ return 0;
+ } else {
+ strncpy(str, password, maxlen);
+ str[maxlen-1] = '\0';
+ tried_once = 1;
+ return 1;
+ }
}
hin = GetStdHandle(STD_INPUT_HANDLE);
}
hin = GetStdHandle(STD_INPUT_HANDLE);
@@
-99,6
+113,8
@@
void ssh_get_password(char *prompt, char *str, int maxlen)
str[i] = '\0';
WriteFile(hout, "\r\n", 2, &i, NULL);
str[i] = '\0';
WriteFile(hout, "\r\n", 2, &i, NULL);
+
+ return 1;
}
/*
}
/*
@@
-134,7
+150,7
@@
static void do_cmd(char *host, char *user, char *cmd)
if (portnumber)
cfg.port = portnumber;
if (portnumber)
cfg.port = portnumber;
- err = ssh_init(cfg.host, cfg.port, cmd, &realhost);
+ err = ssh_
scp_
init(cfg.host, cfg.port, cmd, &realhost);
if (err != NULL)
bump("ssh_init: %s", err);
if (verbose && realhost != NULL)
if (err != NULL)
bump("ssh_init: %s", err);
if (verbose && realhost != NULL)
@@
-209,7
+225,7
@@
static int response(void)
char ch, resp, rbuf[2048];
int p;
char ch, resp, rbuf[2048];
int p;
- if (ssh_recv(&resp, 1) <= 0)
+ if (ssh_
scp_
recv(&resp, 1) <= 0)
bump("Lost connection");
p = 0;
bump("Lost connection");
p = 0;
@@
-222,7
+238,7
@@
static int response(void)
case 1: /* error */
case 2: /* fatal error */
do {
case 1: /* error */
case 2: /* fatal error */
do {
- if (ssh_recv(&ch, 1) <= 0)
+ if (ssh_
scp_
recv(&ch, 1) <= 0)
bump("Protocol error: Lost connection");
rbuf[p++] = ch;
} while (p < sizeof(rbuf) && ch != '\n');
bump("Protocol error: Lost connection");
rbuf[p++] = ch;
} while (p < sizeof(rbuf) && ch != '\n');
@@
-249,7
+265,7
@@
static void run_err(const char *fmt, ...)
strcpy(str, "\01scp: ");
vsprintf(str+strlen(str), fmt, ap);
strcat(str, "\n");
strcpy(str, "\01scp: ");
vsprintf(str+strlen(str), fmt, ap);
strcat(str, "\n");
- ssh_send(str, strlen(str));
+ ssh_s
cp_s
end(str, strlen(str));
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
@@
-321,7
+337,7
@@
static void source(char *src)
TIME_WIN_TO_POSIX(actime, atime);
TIME_WIN_TO_POSIX(wrtime, mtime);
sprintf(buf, "T%lu 0 %lu 0\n", mtime, atime);
TIME_WIN_TO_POSIX(actime, atime);
TIME_WIN_TO_POSIX(wrtime, mtime);
sprintf(buf, "T%lu 0 %lu 0\n", mtime, atime);
- ssh_send(buf, strlen(buf));
+ ssh_s
cp_s
end(buf, strlen(buf));
if (response())
return;
}
if (response())
return;
}
@@
-330,7
+346,7
@@
static void source(char *src)
sprintf(buf, "C0644 %lu %s\n", size, last);
if (verbose)
fprintf(stderr, "Sending file modes: %s", buf);
sprintf(buf, "C0644 %lu %s\n", size, last);
if (verbose)
fprintf(stderr, "Sending file modes: %s", buf);
- ssh_send(buf, strlen(buf));
+ ssh_s
cp_s
end(buf, strlen(buf));
if (response())
return;
if (response())
return;
@@
-348,7
+364,7
@@
static void source(char *src)
if (statistics) printf("\n");
bump("%s: Read error", src);
}
if (statistics) printf("\n");
bump("%s: Read error", src);
}
- ssh_send(transbuf, k);
+ ssh_s
cp_s
end(transbuf, k);
if (statistics) {
stat_bytes += k;
if (time(NULL) != stat_lasttime ||
if (statistics) {
stat_bytes += k;
if (time(NULL) != stat_lasttime ||
@@
-361,7
+377,7
@@
static void source(char *src)
}
CloseHandle(f);
}
CloseHandle(f);
- ssh_send("", 1);
+ ssh_s
cp_s
end("", 1);
(void) response();
}
(void) response();
}
@@
-390,7
+406,7
@@
static void rsource(char *src)
sprintf(buf, "D0755 0 %s\n", last);
if (verbose)
fprintf(stderr, "Entering directory: %s", buf);
sprintf(buf, "D0755 0 %s\n", last);
if (verbose)
fprintf(stderr, "Entering directory: %s", buf);
- ssh_send(buf, strlen(buf));
+ ssh_s
cp_s
end(buf, strlen(buf));
if (response())
return;
if (response())
return;
@@
-412,7
+428,7
@@
static void rsource(char *src)
FindClose(dir);
sprintf(buf, "E\n");
FindClose(dir);
sprintf(buf, "E\n");
- ssh_send(buf, strlen(buf));
+ ssh_s
cp_s
end(buf, strlen(buf));
(void) response();
}
(void) response();
}
@@
-444,18
+460,18
@@
static void sink(char *targ)
if (targetshouldbedirectory && !targisdir)
bump("%s: Not a directory", targ);
if (targetshouldbedirectory && !targisdir)
bump("%s: Not a directory", targ);
- ssh_send("", 1);
+ ssh_s
cp_s
end("", 1);
while (1) {
settime = 0;
gottime:
while (1) {
settime = 0;
gottime:
- if (ssh_recv(&ch, 1) <= 0)
+ if (ssh_
scp_
recv(&ch, 1) <= 0)
return;
if (ch == '\n')
bump("Protocol error: Unexpected newline");
i = 0;
buf[i++] = ch;
do {
return;
if (ch == '\n')
bump("Protocol error: Unexpected newline");
i = 0;
buf[i++] = ch;
do {
- if (ssh_recv(&ch, 1) <= 0)
+ if (ssh_
scp_
recv(&ch, 1) <= 0)
bump("Lost connection");
buf[i++] = ch;
} while (i < sizeof(buf) && ch != '\n');
bump("Lost connection");
buf[i++] = ch;
} while (i < sizeof(buf) && ch != '\n');
@@
-468,13
+484,13
@@
static void sink(char *targ)
case '\02': /* fatal error */
bump("%s", buf+1);
case 'E':
case '\02': /* fatal error */
bump("%s", buf+1);
case 'E':
- ssh_send("", 1);
+ ssh_s
cp_s
end("", 1);
return;
case 'T':
if (sscanf(buf, "T%ld %*d %ld %*d",
&mtime, &atime) == 2) {
settime = 1;
return;
case 'T':
if (sscanf(buf, "T%ld %*d %ld %*d",
&mtime, &atime) == 2) {
settime = 1;
- ssh_send("", 1);
+ ssh_s
cp_s
end("", 1);
goto gottime;
}
bump("Protocol error: Illegal time format");
goto gottime;
}
bump("Protocol error: Illegal time format");
@@
-524,7
+540,7
@@
static void sink(char *targ)
continue;
}
continue;
}
- ssh_send("", 1);
+ ssh_s
cp_s
end("", 1);
if (statistics) {
stat_bytes = 0;
if (statistics) {
stat_bytes = 0;
@@
-542,7
+558,7
@@
static void sink(char *targ)
char transbuf[4096];
DWORD j, k = 4096;
if (i + k > size) k = size - i;
char transbuf[4096];
DWORD j, k = 4096;
if (i + k > size) k = size - i;
- if (ssh_recv(transbuf, k) == 0)
+ if (ssh_
scp_
recv(transbuf, k) == 0)
bump("Lost connection");
if (wrerror) continue;
if (! WriteFile(f, transbuf, k, &j, NULL) || j != k) {
bump("Lost connection");
if (wrerror) continue;
if (! WriteFile(f, transbuf, k, &j, NULL) || j != k) {
@@
-577,7
+593,7
@@
static void sink(char *targ)
run_err("%s: Write error", namebuf);
continue;
}
run_err("%s: Write error", namebuf);
continue;
}
- ssh_send("", 1);
+ ssh_s
cp_s
end("", 1);
}
}
}
}
@@
-778,7
+794,7
@@
static void get_dir_list(int argc, char *argv[])
do_cmd(host, user, cmd);
sfree(cmd);
do_cmd(host, user, cmd);
sfree(cmd);
- while (ssh_recv(&c, 1) > 0)
+ while (ssh_
scp_
recv(&c, 1) > 0)
fputc(c, stdout); /* thank heavens for buffered I/O */
}
fputc(c, stdout); /* thank heavens for buffered I/O */
}
@@
-805,9
+821,9
@@
static void usage(void)
{
printf("PuTTY Secure Copy client\n");
printf("%s\n", ver);
{
printf("PuTTY Secure Copy client\n");
printf("%s\n", ver);
- printf("Usage: scp [options] [user@]host:source target\n");
- printf(" scp [options] source [source...] [user@]host:target\n");
- printf(" scp [options] -ls user@host:filespec\n");
+ printf("Usage:
p
scp [options] [user@]host:source target\n");
+ printf("
p
scp [options] source [source...] [user@]host:target\n");
+ printf("
p
scp [options] -ls user@host:filespec\n");
printf("Options:\n");
printf(" -p preserve file attributes\n");
printf(" -q quiet, don't show statistics\n");
printf("Options:\n");
printf(" -p preserve file attributes\n");
printf(" -q quiet, don't show statistics\n");
@@
-826,13
+842,17
@@
int main(int argc, char *argv[])
int i;
int list = 0;
int i;
int list = 0;
+ default_protocol = PROT_TELNET;
+
+ flags = 0;
+ ssh_get_password = &get_password;
init_winsock();
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
if (strcmp(argv[i], "-v") == 0)
init_winsock();
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
if (strcmp(argv[i], "-v") == 0)
- verbose = 1;
+ verbose = 1
, flags |= FLAG_VERBOSE
;
else if (strcmp(argv[i], "-r") == 0)
recursive = 1;
else if (strcmp(argv[i], "-p") == 0)
else if (strcmp(argv[i], "-r") == 0)
recursive = 1;
else if (strcmp(argv[i], "-p") == 0)
@@
-876,8
+896,8
@@
int main(int argc, char *argv[])
if (connection_open) {
char ch;
if (connection_open) {
char ch;
- ssh_send_eof();
- ssh_recv(&ch, 1);
+ ssh_s
cp_s
end_eof();
+ ssh_
scp_
recv(&ch, 1);
}
WSACleanup();
random_save_seed();
}
WSACleanup();
random_save_seed();
@@
-886,3
+906,4
@@
int main(int argc, char *argv[])
}
/* end */
}
/* end */
+