| ︙ | | | ︙ | |
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
* (SGT, 2001-09-10: Joris van Rantwijk assures me that although
* this file as originally submitted was inspired by, and
* _structurally_ based on, ssh-1.2.26's scp.c, there wasn't any
* actual code duplicated, so the above comment shouldn't give rise
* to licensing issues.)
*/
#include <windows.h>
#ifndef AUTO_WINSOCK
#ifdef WINSOCK_TWO
#include <winsock2.h>
#else
#include <winsock.h>
#endif
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <assert.h>
#define PUTTY_DO_GLOBALS
#include "putty.h"
#include "ssh.h"
#include "sftp.h"
#include "winstuff.h"
#include "storage.h"
#define TIME_POSIX_TO_WIN(t, ft) (*(LONGLONG*)&(ft) = \
((LONGLONG) (t) + (LONGLONG) 11644473600) * (LONGLONG) 10000000)
#define TIME_WIN_TO_POSIX(ft, t) ((t) = (unsigned long) \
((*(LONGLONG*)&(ft)) / (LONGLONG) 10000000 - (LONGLONG) 11644473600))
/* GUI Adaptation - Sept 2000 */
/* This is just a base value from which the main message numbers are
* derived. */
#define WM_APP_BASE 0x8000
/* These two pass a single character value in wParam. They represent
* the visible output from PSCP. */
#define WM_STD_OUT_CHAR ( WM_APP_BASE+400 )
#define WM_STD_ERR_CHAR ( WM_APP_BASE+401 )
/* These pass a transfer status update. WM_STATS_CHAR passes a single
* character in wParam, and is called repeatedly to pass the name of
* the file, terminated with "\n". WM_STATS_SIZE passes the size of
* the file being transferred in wParam. WM_STATS_ELAPSED is called
* to pass the elapsed time (in seconds) in wParam, and
* WM_STATS_PERCENT passes the percentage of the transfer which is
* complete, also in wParam. */
#define WM_STATS_CHAR ( WM_APP_BASE+402 )
#define WM_STATS_SIZE ( WM_APP_BASE+403 )
#define WM_STATS_PERCENT ( WM_APP_BASE+404 )
#define WM_STATS_ELAPSED ( WM_APP_BASE+405 )
/* These are used at the end of a run to pass an error code in
* wParam: zero means success, nonzero means failure. WM_RET_ERR_CNT
* is used after a copy, and WM_LS_RET_ERR_CNT is used after a file
* list operation. */
#define WM_RET_ERR_CNT ( WM_APP_BASE+406 )
#define WM_LS_RET_ERR_CNT ( WM_APP_BASE+407 )
/* More transfer status update messages. WM_STATS_DONE passes the
* number of bytes sent so far in wParam. WM_STATS_ETA passes the
* estimated time to completion (in seconds). WM_STATS_RATEBS passes
* the average transfer rate (in bytes per second). */
#define WM_STATS_DONE ( WM_APP_BASE+408 )
#define WM_STATS_ETA ( WM_APP_BASE+409 )
#define WM_STATS_RATEBS ( WM_APP_BASE+410 )
static int list = 0;
static int verbose = 0;
static int recursive = 0;
static int preserve = 0;
static int targetshouldbedirectory = 0;
static int statistics = 1;
static int prev_stats_len = 0;
static int scp_unsafe_mode = 0;
static int errs = 0;
/* GUI Adaptation - Sept 2000 */
#define NAME_STR_MAX 2048
static char statname[NAME_STR_MAX + 1];
static unsigned long statsize = 0;
static unsigned long statdone = 0;
static unsigned long stateta = 0;
static unsigned long statratebs = 0;
static int statperct = 0;
static unsigned long statelapsed = 0;
static int gui_mode = 0;
static char *gui_hwnd = NULL;
static int using_sftp = 0;
static Backend *back;
static void *backhandle;
static Config cfg;
static void source(char *src);
static void rsource(char *src);
static void sink(char *targ, char *src);
/* GUI Adaptation - Sept 2000 */
static void tell_char(FILE * stream, char c);
static void tell_str(FILE * stream, char *str);
static void tell_user(FILE * stream, char *fmt, ...);
static void gui_update_stats(char *name, unsigned long size,
int percentage, unsigned long elapsed,
unsigned long done, unsigned long eta,
unsigned long ratebs);
/*
* The maximum amount of queued data we accept before we stop and
* wait for the server to process some.
*/
#define MAX_SCP_BUFSIZE 16384
void ldisc_send(void *handle, char *buf, int len, int interactive)
{
/*
* This is only here because of the calls to ldisc_send(NULL,
* 0) in ssh.c. Nothing in PSCP actually needs to use the ldisc
* as an ldisc. So if we get called with any real data, I want
* to know about it.
*/
assert(len == 0);
}
/* GUI Adaptation - Sept 2000 */
static void send_msg(HWND h, UINT message, WPARAM wParam)
{
while (!PostMessage(h, message, wParam, 0))
SleepEx(1000, TRUE);
}
static void tell_char(FILE * stream, char c)
{
if (!gui_mode)
fputc(c, stream);
else {
unsigned int msg_id = WM_STD_OUT_CHAR;
if (stream == stderr)
msg_id = WM_STD_ERR_CHAR;
send_msg((HWND) atoi(gui_hwnd), msg_id, (WPARAM) c);
}
}
static void tell_str(FILE * stream, char *str)
{
unsigned int i;
for (i = 0; i < strlen(str); ++i)
|
<
<
<
<
<
<
<
<
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
<
<
<
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
* (SGT, 2001-09-10: Joris van Rantwijk assures me that although
* this file as originally submitted was inspired by, and
* _structurally_ based on, ssh-1.2.26's scp.c, there wasn't any
* actual code duplicated, so the above comment shouldn't give rise
* to licensing issues.)
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <assert.h>
#define PUTTY_DO_GLOBALS
#include "putty.h"
#include "psftp.h"
#include "ssh.h"
#include "sftp.h"
#include "storage.h"
static int list = 0;
static int verbose = 0;
static int recursive = 0;
static int preserve = 0;
static int targetshouldbedirectory = 0;
static int statistics = 1;
static int prev_stats_len = 0;
static int scp_unsafe_mode = 0;
static int errs = 0;
static int gui_mode = 0;
static int using_sftp = 0;
static Backend *back;
static void *backhandle;
static Config cfg;
static void source(char *src);
static void rsource(char *src);
static void sink(char *targ, char *src);
/*
* The maximum amount of queued data we accept before we stop and
* wait for the server to process some.
*/
#define MAX_SCP_BUFSIZE 16384
void ldisc_send(void *handle, char *buf, int len, int interactive)
{
/*
* This is only here because of the calls to ldisc_send(NULL,
* 0) in ssh.c. Nothing in PSCP actually needs to use the ldisc
* as an ldisc. So if we get called with any real data, I want
* to know about it.
*/
assert(len == 0);
}
static void tell_char(FILE * stream, char c)
{
if (!gui_mode)
fputc(c, stream);
else
gui_send_char(stream == stderr, c);
}
static void tell_str(FILE * stream, char *str)
{
unsigned int i;
for (i = 0; i < strlen(str); ++i)
|
| ︙ | | | ︙ | |
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
va_end(ap);
str2 = dupcat(str, "\n", NULL);
sfree(str);
tell_str(stream, str2);
sfree(str2);
}
static void gui_update_stats(char *name, unsigned long size,
int percentage, unsigned long elapsed,
unsigned long done, unsigned long eta,
unsigned long ratebs)
{
unsigned int i;
if (strcmp(name, statname) != 0) {
for (i = 0; i < strlen(name); ++i)
send_msg((HWND) atoi(gui_hwnd), WM_STATS_CHAR,
(WPARAM) name[i]);
send_msg((HWND) atoi(gui_hwnd), WM_STATS_CHAR, (WPARAM) '\n');
strcpy(statname, name);
}
if (statsize != size) {
send_msg((HWND) atoi(gui_hwnd), WM_STATS_SIZE, (WPARAM) size);
statsize = size;
}
if (statdone != done) {
send_msg((HWND) atoi(gui_hwnd), WM_STATS_DONE, (WPARAM) done);
statdone = done;
}
if (stateta != eta) {
send_msg((HWND) atoi(gui_hwnd), WM_STATS_ETA, (WPARAM) eta);
stateta = eta;
}
if (statratebs != ratebs) {
send_msg((HWND) atoi(gui_hwnd), WM_STATS_RATEBS, (WPARAM) ratebs);
statratebs = ratebs;
}
if (statelapsed != elapsed) {
send_msg((HWND) atoi(gui_hwnd), WM_STATS_ELAPSED,
(WPARAM) elapsed);
statelapsed = elapsed;
}
if (statperct != percentage) {
send_msg((HWND) atoi(gui_hwnd), WM_STATS_PERCENT,
(WPARAM) percentage);
statperct = percentage;
}
}
/*
* Print an error message and perform a fatal exit.
*/
void fatalbox(char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
tell_str(stderr, str2);
sfree(str2);
errs++;
if (gui_mode) {
unsigned int msg_id = WM_RET_ERR_CNT;
if (list)
msg_id = WM_LS_RET_ERR_CNT;
while (!PostMessage
((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
0 /*lParam */ ))SleepEx(1000, TRUE);
}
cleanup_exit(1);
}
void modalfatalbox(char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
tell_str(stderr, str2);
sfree(str2);
errs++;
if (gui_mode) {
unsigned int msg_id = WM_RET_ERR_CNT;
if (list)
msg_id = WM_LS_RET_ERR_CNT;
while (!PostMessage
((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
0 /*lParam */ ))SleepEx(1000, TRUE);
}
cleanup_exit(1);
}
void connection_fatal(void *frontend, char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
tell_str(stderr, str2);
sfree(str2);
errs++;
if (gui_mode) {
unsigned int msg_id = WM_RET_ERR_CNT;
if (list)
msg_id = WM_LS_RET_ERR_CNT;
while (!PostMessage
((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
0 /*lParam */ ))SleepEx(1000, TRUE);
}
cleanup_exit(1);
}
/*
* Be told what socket we're supposed to be using.
*/
static SOCKET scp_ssh_socket;
char *do_select(SOCKET skt, int startup)
{
if (startup)
scp_ssh_socket = skt;
else
scp_ssh_socket = INVALID_SOCKET;
return NULL;
}
extern int select_result(WPARAM, LPARAM);
/*
* In pscp, all agent requests should be synchronous, so this is a
* never-called stub.
*/
void agent_schedule_callback(void (*callback)(void *, void *, int),
void *callback_ctx, void *data, int len)
{
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
<
<
<
<
<
|
<
|
<
<
<
<
<
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
va_end(ap);
str2 = dupcat(str, "\n", NULL);
sfree(str);
tell_str(stream, str2);
sfree(str2);
}
/*
* Print an error message and perform a fatal exit.
*/
void fatalbox(char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
tell_str(stderr, str2);
sfree(str2);
errs++;
if (gui_mode)
gui_send_errcount(list, errs);
cleanup_exit(1);
}
void modalfatalbox(char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
tell_str(stderr, str2);
sfree(str2);
errs++;
if (gui_mode)
gui_send_errcount(list, errs);
cleanup_exit(1);
}
void connection_fatal(void *frontend, char *fmt, ...)
{
char *str, *str2;
va_list ap;
va_start(ap, fmt);
str = dupvprintf(fmt, ap);
str2 = dupcat("Fatal: ", str, "\n", NULL);
sfree(str);
va_end(ap);
tell_str(stderr, str2);
sfree(str2);
errs++;
if (gui_mode)
gui_send_errcount(list, errs);
cleanup_exit(1);
}
/*
* In pscp, all agent requests should be synchronous, so this is a
* never-called stub.
*/
void agent_schedule_callback(void (*callback)(void *, void *, int),
void *callback_ctx, void *data, int len)
{
|
| ︙ | | | ︙ | |
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
}
memcpy(pending + pendlen, p, len);
pendlen += len;
}
return 0;
}
static int scp_process_network_event(void)
{
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(scp_ssh_socket, &readfds);
if (select(1, &readfds, NULL, NULL, NULL) < 0)
return 0; /* doom */
select_result((WPARAM) scp_ssh_socket, (LPARAM) FD_READ);
return 1;
}
static int ssh_scp_recv(unsigned char *buf, int len)
{
outptr = buf;
outlen = len;
/*
* See if the pending-input block contains some of what we
|
<
<
<
<
<
<
<
<
<
<
<
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
}
memcpy(pending + pendlen, p, len);
pendlen += len;
}
return 0;
}
static int ssh_scp_recv(unsigned char *buf, int len)
{
outptr = buf;
outlen = len;
/*
* See if the pending-input block contains some of what we
|
| ︙ | | | ︙ | |
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
pending = NULL;
}
if (outlen == 0)
return len;
}
while (outlen > 0) {
if (!scp_process_network_event())
return 0; /* doom */
}
return len;
}
/*
* Loop through the ssh connection and authentication process.
*/
static void ssh_scp_init(void)
{
if (scp_ssh_socket == INVALID_SOCKET)
return;
while (!back->sendok(backhandle)) {
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(scp_ssh_socket, &readfds);
if (select(1, &readfds, NULL, NULL, NULL) < 0)
return; /* doom */
select_result((WPARAM) scp_ssh_socket, (LPARAM) FD_READ);
}
using_sftp = !ssh_fallback_cmd(backhandle);
if (verbose) {
if (using_sftp)
tell_user(stderr, "Using SFTP");
else
tell_user(stderr, "Using SCP1");
|
|
<
<
<
<
|
<
<
|
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
pending = NULL;
}
if (outlen == 0)
return len;
}
while (outlen > 0) {
if (ssh_sftp_loop_iteration() < 0)
return 0; /* doom */
}
return len;
}
/*
* Loop through the ssh connection and authentication process.
*/
static void ssh_scp_init(void)
{
while (!back->sendok(backhandle)) {
if (ssh_sftp_loop_iteration() < 0)
return; /* doom */
}
using_sftp = !ssh_fallback_cmd(backhandle);
if (verbose) {
if (using_sftp)
tell_user(stderr, "Using SFTP");
else
tell_user(stderr, "Using SCP1");
|
| ︙ | | | ︙ | |
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
if (back != NULL && back->socket(backhandle) != NULL) {
char ch;
back->special(backhandle, TS_EOF);
ssh_scp_recv(&ch, 1);
}
if (gui_mode) {
unsigned int msg_id = WM_RET_ERR_CNT;
if (list)
msg_id = WM_LS_RET_ERR_CNT;
while (!PostMessage
((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
0 /*lParam */ ))SleepEx(1000, TRUE);
}
cleanup_exit(1);
}
/*
* Open an SSH connection to user@host and execute cmd.
*/
static void do_cmd(char *host, char *user, char *cmd)
{
const char *err;
char *realhost;
DWORD namelen;
if (host == NULL || host[0] == '\0')
bump("Empty host name");
/* Try to load settings for this host */
do_defaults(host, &cfg);
if (cfg.host[0] == '\0') {
|
|
<
|
<
<
<
<
<
|
|
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
if (back != NULL && back->socket(backhandle) != NULL) {
char ch;
back->special(backhandle, TS_EOF);
ssh_scp_recv(&ch, 1);
}
if (gui_mode)
gui_send_errcount(list, errs);
cleanup_exit(1);
}
/*
* Open an SSH connection to user@host and execute cmd.
*/
static void do_cmd(char *host, char *user, char *cmd)
{
const char *err;
char *realhost;
void *logctx;
if (host == NULL || host[0] == '\0')
bump("Empty host name");
/* Try to load settings for this host */
do_defaults(host, &cfg);
if (cfg.host[0] == '\0') {
|
| ︙ | | | ︙ | |
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
}
/* Set username */
if (user != NULL && user[0] != '\0') {
strncpy(cfg.username, user, sizeof(cfg.username) - 1);
cfg.username[sizeof(cfg.username) - 1] = '\0';
} else if (cfg.username[0] == '\0') {
namelen = 0;
if (GetUserName(user, &namelen) == FALSE)
bump("Empty user name");
user = snewn(namelen, char);
GetUserName(user, &namelen);
if (verbose)
tell_user(stderr, "Guessing user name: %s", user);
strncpy(cfg.username, user, sizeof(cfg.username) - 1);
cfg.username[sizeof(cfg.username) - 1] = '\0';
free(user);
}
/*
* Disable scary things which shouldn't be enabled for simple
* things like SCP and SFTP: agent forwarding, port forwarding,
* X forwarding.
*/
|
|
|
|
<
|
|
|
|
|
>
|
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
}
/* Set username */
if (user != NULL && user[0] != '\0') {
strncpy(cfg.username, user, sizeof(cfg.username) - 1);
cfg.username[sizeof(cfg.username) - 1] = '\0';
} else if (cfg.username[0] == '\0') {
user = get_username();
if (!user)
bump("Empty user name");
else {
if (verbose)
tell_user(stderr, "Guessing user name: %s", user);
strncpy(cfg.username, user, sizeof(cfg.username) - 1);
cfg.username[sizeof(cfg.username) - 1] = '\0';
sfree(user);
}
}
/*
* Disable scary things which shouldn't be enabled for simple
* things like SCP and SFTP: agent forwarding, port forwarding,
* X forwarding.
*/
|
| ︙ | | | ︙ | |
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
else
eta = (unsigned long) ((size - done) / ratebs);
sprintf(etastr, "%02ld:%02ld:%02ld",
eta / 3600, (eta % 3600) / 60, eta % 60);
pct = (int) (100 * (done * 1.0 / size));
if (gui_mode)
/* GUI Adaptation - Sept 2000 */
gui_update_stats(name, size, pct, elap, done, eta,
(unsigned long) ratebs);
else {
len = printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%",
name, done / 1024, ratebs / 1024.0, etastr, pct);
if (len < prev_stats_len)
printf("%*s", prev_stats_len - len, "");
prev_stats_len = len;
if (done == size)
|
|
<
|
|
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
else
eta = (unsigned long) ((size - done) / ratebs);
sprintf(etastr, "%02ld:%02ld:%02ld",
eta / 3600, (eta % 3600) / 60, eta % 60);
pct = (int) (100 * (done * 1.0 / size));
if (gui_mode) {
gui_update_stats(name, size, pct, elap, done, eta,
(unsigned long) ratebs);
} else {
len = printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%",
name, done / 1024, ratebs / 1024.0, etastr, pct);
if (len < prev_stats_len)
printf("%*s", prev_stats_len - len, "");
prev_stats_len = len;
if (done == size)
|
| ︙ | | | ︙ | |
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
|
/*
* If the network transfer is backing up - that is, the
* remote site is not accepting data as fast as we can
* produce it - then we must loop on network events until
* we have space in the buffer again.
*/
while (bufsize > MAX_SCP_BUFSIZE) {
if (!scp_process_network_event())
return 1;
bufsize = back->sendbuffer(backhandle);
}
return 0;
}
}
|
|
|
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
|
/*
* If the network transfer is backing up - that is, the
* remote site is not accepting data as fast as we can
* produce it - then we must loop on network events until
* we have space in the buffer again.
*/
while (bufsize > MAX_SCP_BUFSIZE) {
if (ssh_sftp_loop_iteration() < 0)
return 1;
bufsize = back->sendbuffer(backhandle);
}
return 0;
}
}
|
| ︙ | | | ︙ | |
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
|
/*
* Execute the source part of the SCP protocol.
*/
static void source(char *src)
{
unsigned long size;
char *last;
HANDLE f;
DWORD attr;
unsigned long i;
unsigned long stat_bytes;
time_t stat_starttime, stat_lasttime;
attr = GetFileAttributes(src);
if (attr == (DWORD) - 1) {
run_err("%s: No such file or directory", src);
return;
}
if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
if (recursive) {
/*
* Avoid . and .. directories.
*/
char *p;
p = strrchr(src, '/');
if (!p)
|
>
|
|
|
|
>
|
>
|
|
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
|
/*
* Execute the source part of the SCP protocol.
*/
static void source(char *src)
{
unsigned long size;
unsigned long mtime, atime;
char *last;
RFile *f;
int attr;
unsigned long i;
unsigned long stat_bytes;
time_t stat_starttime, stat_lasttime;
attr = file_type(src);
if (attr == FILE_TYPE_NONEXISTENT ||
attr == FILE_TYPE_WEIRD) {
run_err("%s: %s file or directory", src,
(attr == FILE_TYPE_WEIRD ? "Not a" : "No such"));
return;
}
if (attr == FILE_TYPE_DIRECTORY) {
if (recursive) {
/*
* Avoid . and .. directories.
*/
char *p;
p = strrchr(src, '/');
if (!p)
|
| ︙ | | | ︙ | |
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
|
else
last++;
if (strrchr(last, '\\') != NULL)
last = strrchr(last, '\\') + 1;
if (last == src && strchr(src, ':') != NULL)
last = strchr(src, ':') + 1;
f = CreateFile(src, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, 0);
if (f == INVALID_HANDLE_VALUE) {
run_err("%s: Cannot open file", src);
return;
}
if (preserve) {
FILETIME actime, wrtime;
unsigned long mtime, atime;
GetFileTime(f, NULL, &actime, &wrtime);
TIME_WIN_TO_POSIX(actime, atime);
TIME_WIN_TO_POSIX(wrtime, mtime);
if (scp_send_filetimes(mtime, atime))
return;
}
size = GetFileSize(f, NULL);
if (verbose)
tell_user(stderr, "Sending file %s, size=%lu", last, size);
if (scp_send_filename(last, size, 0644))
return;
stat_bytes = 0;
stat_starttime = time(NULL);
stat_lasttime = 0;
for (i = 0; i < size; i += 4096) {
char transbuf[4096];
DWORD j, k = 4096;
if (i + k > size)
k = size - i;
if (!ReadFile(f, transbuf, k, &j, NULL) || j != k) {
if (statistics)
printf("\n");
bump("%s: Read error", src);
}
if (scp_send_filedata(transbuf, k))
bump("%s: Network error occurred", src);
if (statistics) {
stat_bytes += k;
if (time(NULL) != stat_lasttime || i + k == size) {
stat_lasttime = time(NULL);
print_stats(last, size, stat_bytes,
stat_starttime, stat_lasttime);
}
}
}
CloseHandle(f);
(void) scp_send_finish();
}
/*
* Recursively send the contents of a directory.
*/
static void rsource(char *src)
{
char *last, *findfile;
char *save_target;
HANDLE dir;
WIN32_FIND_DATA fdat;
int ok;
if ((last = strrchr(src, '/')) == NULL)
last = src;
else
last++;
if (strrchr(last, '\\') != NULL)
last = strrchr(last, '\\') + 1;
if (last == src && strchr(src, ':') != NULL)
last = strchr(src, ':') + 1;
/* maybe send filetime */
save_target = scp_save_remotepath();
if (verbose)
tell_user(stderr, "Entering directory: %s", last);
if (scp_send_dirname(last, 0755))
return;
findfile = dupcat(src, "/*", NULL);
dir = FindFirstFile(findfile, &fdat);
ok = (dir != INVALID_HANDLE_VALUE);
while (ok) {
if (strcmp(fdat.cFileName, ".") == 0 ||
strcmp(fdat.cFileName, "..") == 0) {
/* ignore . and .. */
} else {
char *foundfile = dupcat(src, "/", fdat.cFileName, NULL);
source(foundfile);
sfree(foundfile);
}
ok = FindNextFile(dir, &fdat);
}
FindClose(dir);
sfree(findfile);
(void) scp_send_enddir();
scp_restore_remotepath(save_target);
}
/*
* Execute the sink part of the SCP protocol.
*/
static void sink(char *targ, char *src)
{
char *destfname;
int targisdir = 0;
int exists;
DWORD attr;
HANDLE f;
unsigned long received;
int wrerror = 0;
unsigned long stat_bytes;
time_t stat_starttime, stat_lasttime;
char *stat_name;
attr = GetFileAttributes(targ);
if (attr != (DWORD) - 1 && (attr & FILE_ATTRIBUTE_DIRECTORY) != 0)
targisdir = 1;
if (targetshouldbedirectory && !targisdir)
bump("%s: Not a directory", targ);
scp_sink_init();
while (1) {
|
|
<
|
<
<
<
<
<
<
<
|
|
|
|
|
<
<
<
|
|
>
|
<
<
<
<
|
>
<
|
<
|
|
|
|
|
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
|
else
last++;
if (strrchr(last, '\\') != NULL)
last = strrchr(last, '\\') + 1;
if (last == src && strchr(src, ':') != NULL)
last = strchr(src, ':') + 1;
f = open_existing_file(src, &size, &mtime, &atime);
if (f == NULL) {
run_err("%s: Cannot open file", src);
return;
}
if (preserve) {
if (scp_send_filetimes(mtime, atime))
return;
}
if (verbose)
tell_user(stderr, "Sending file %s, size=%lu", last, size);
if (scp_send_filename(last, size, 0644))
return;
stat_bytes = 0;
stat_starttime = time(NULL);
stat_lasttime = 0;
for (i = 0; i < size; i += 4096) {
char transbuf[4096];
int j, k = 4096;
if (i + k > size)
k = size - i;
if ((j = read_from_file(f, transbuf, k)) != k) {
if (statistics)
printf("\n");
bump("%s: Read error", src);
}
if (scp_send_filedata(transbuf, k))
bump("%s: Network error occurred", src);
if (statistics) {
stat_bytes += k;
if (time(NULL) != stat_lasttime || i + k == size) {
stat_lasttime = time(NULL);
print_stats(last, size, stat_bytes,
stat_starttime, stat_lasttime);
}
}
}
close_rfile(f);
(void) scp_send_finish();
}
/*
* Recursively send the contents of a directory.
*/
static void rsource(char *src)
{
char *last;
char *save_target;
DirHandle *dir;
if ((last = strrchr(src, '/')) == NULL)
last = src;
else
last++;
if (strrchr(last, '\\') != NULL)
last = strrchr(last, '\\') + 1;
if (last == src && strchr(src, ':') != NULL)
last = strchr(src, ':') + 1;
/* maybe send filetime */
save_target = scp_save_remotepath();
if (verbose)
tell_user(stderr, "Entering directory: %s", last);
if (scp_send_dirname(last, 0755))
return;
dir = open_directory(src);
if (dir != NULL) {
char *filename;
while ((filename = read_filename(dir)) != NULL) {
char *foundfile = dupcat(src, "/", filename, NULL);
source(foundfile);
sfree(foundfile);
sfree(filename);
}
}
close_directory(dir);
(void) scp_send_enddir();
scp_restore_remotepath(save_target);
}
/*
* Execute the sink part of the SCP protocol.
*/
static void sink(char *targ, char *src)
{
char *destfname;
int targisdir = 0;
int exists;
int attr;
WFile *f;
unsigned long received;
int wrerror = 0;
unsigned long stat_bytes;
time_t stat_starttime, stat_lasttime;
char *stat_name;
attr = file_type(targ);
if (attr == FILE_TYPE_DIRECTORY)
targisdir = 1;
if (targetshouldbedirectory && !targisdir)
bump("%s: Not a directory", targ);
scp_sink_init();
while (1) {
|
| ︙ | | | ︙ | |
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
|
/*
* In this branch of the if, the target area is a
* single file with an explicitly specified name in any
* case, so there's no danger.
*/
destfname = dupstr(targ);
}
attr = GetFileAttributes(destfname);
exists = (attr != (DWORD) - 1);
if (act.action == SCP_SINK_DIR) {
if (exists && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
run_err("%s: Not a directory", destfname);
continue;
}
if (!exists) {
if (!CreateDirectory(destfname, NULL)) {
run_err("%s: Cannot create directory", destfname);
continue;
}
}
sink(destfname, NULL);
/* can we set the timestamp for directories ? */
continue;
}
f = CreateFile(destfname, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (f == INVALID_HANDLE_VALUE) {
run_err("%s: Cannot create file", destfname);
continue;
}
if (scp_accept_filexfer())
return;
stat_bytes = 0;
stat_starttime = time(NULL);
stat_lasttime = 0;
stat_name = stripslashes(destfname, 1);
received = 0;
while (received < act.size) {
char transbuf[4096];
DWORD blksize, read, written;
blksize = 4096;
if (blksize > act.size - received)
blksize = act.size - received;
read = scp_recv_filedata(transbuf, blksize);
if (read <= 0)
bump("Lost connection");
if (wrerror)
continue;
if (!WriteFile(f, transbuf, read, &written, NULL) ||
written != read) {
wrerror = 1;
/* FIXME: in sftp we can actually abort the transfer */
if (statistics)
printf("\r%-25.25s | %50s\n",
stat_name,
"Write error.. waiting for end of file");
continue;
}
if (statistics) {
stat_bytes += read;
if (time(NULL) > stat_lasttime ||
received + read == act.size) {
stat_lasttime = time(NULL);
print_stats(stat_name, act.size, stat_bytes,
stat_starttime, stat_lasttime);
}
}
received += read;
}
if (act.settime) {
FILETIME actime, wrtime;
TIME_POSIX_TO_WIN(act.atime, actime);
TIME_POSIX_TO_WIN(act.mtime, wrtime);
SetFileTime(f, NULL, &actime, &wrtime);
}
CloseHandle(f);
if (wrerror) {
run_err("%s: Write error", destfname);
continue;
}
(void) scp_finish_filerecv();
sfree(destfname);
sfree(act.buf);
}
}
/*
* We will copy local files to a remote server.
*/
static void toremote(int argc, char *argv[])
{
char *src, *targ, *host, *user;
char *cmd;
int i;
targ = argv[argc - 1];
/* Separate host from filename */
host = targ;
targ = colon(targ);
if (targ == NULL)
|
|
|
|
|
|
<
|
|
|
|
<
<
<
|
<
|
|
|
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
|
/*
* In this branch of the if, the target area is a
* single file with an explicitly specified name in any
* case, so there's no danger.
*/
destfname = dupstr(targ);
}
attr = file_type(destfname);
exists = (attr != FILE_TYPE_NONEXISTENT);
if (act.action == SCP_SINK_DIR) {
if (exists && attr != FILE_TYPE_DIRECTORY) {
run_err("%s: Not a directory", destfname);
continue;
}
if (!exists) {
if (!create_directory(destfname)) {
run_err("%s: Cannot create directory", destfname);
continue;
}
}
sink(destfname, NULL);
/* can we set the timestamp for directories ? */
continue;
}
f = open_new_file(destfname);
if (f == NULL) {
run_err("%s: Cannot create file", destfname);
continue;
}
if (scp_accept_filexfer())
return;
stat_bytes = 0;
stat_starttime = time(NULL);
stat_lasttime = 0;
stat_name = stripslashes(destfname, 1);
received = 0;
while (received < act.size) {
char transbuf[4096];
int blksize, read;
blksize = 4096;
if (blksize > (int)(act.size - received))
blksize = act.size - received;
read = scp_recv_filedata(transbuf, blksize);
if (read <= 0)
bump("Lost connection");
if (wrerror)
continue;
if (write_to_file(f, transbuf, read) != (int)read) {
wrerror = 1;
/* FIXME: in sftp we can actually abort the transfer */
if (statistics)
printf("\r%-25.25s | %50s\n",
stat_name,
"Write error.. waiting for end of file");
continue;
}
if (statistics) {
stat_bytes += read;
if (time(NULL) > stat_lasttime ||
received + read == act.size) {
stat_lasttime = time(NULL);
print_stats(stat_name, act.size, stat_bytes,
stat_starttime, stat_lasttime);
}
}
received += read;
}
if (act.settime) {
set_file_times(f, act.mtime, act.atime);
}
close_wfile(f);
if (wrerror) {
run_err("%s: Write error", destfname);
continue;
}
(void) scp_finish_filerecv();
sfree(destfname);
sfree(act.buf);
}
}
/*
* We will copy local files to a remote server.
*/
static void toremote(int argc, char *argv[])
{
char *src, *targ, *host, *user;
char *cmd;
int i, wc_type;
targ = argv[argc - 1];
/* Separate host from filename */
host = targ;
targ = colon(targ);
if (targ == NULL)
|
| ︙ | | | ︙ | |
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
|
} else {
*host++ = '\0';
if (*user == '\0')
user = NULL;
}
if (argc == 2) {
/* Find out if the source filespec covers multiple files
if so, we should set the targetshouldbedirectory flag */
HANDLE fh;
WIN32_FIND_DATA fdat;
if (colon(argv[0]) != NULL)
bump("%s: Remote to remote not supported", argv[0]);
fh = FindFirstFile(argv[0], &fdat);
if (fh == INVALID_HANDLE_VALUE)
bump("%s: No such file or directory\n", argv[0]);
if (FindNextFile(fh, &fdat))
targetshouldbedirectory = 1;
FindClose(fh);
}
cmd = dupprintf("scp%s%s%s%s -t %s",
verbose ? " -v" : "",
recursive ? " -r" : "",
preserve ? " -p" : "",
targetshouldbedirectory ? " -d" : "", targ);
do_cmd(host, user, cmd);
sfree(cmd);
scp_source_setup(targ, targetshouldbedirectory);
for (i = 0; i < argc - 1; i++) {
char *srcpath, *last;
HANDLE dir;
WIN32_FIND_DATA fdat;
src = argv[i];
if (colon(src) != NULL) {
tell_user(stderr, "%s: Remote to remote not supported\n", src);
errs++;
continue;
}
/*
* Trim off the last pathname component of `src', to
* provide the base pathname which will be prepended to
* filenames returned from Find{First,Next}File.
*/
srcpath = dupstr(src);
last = stripslashes(srcpath, 1);
*last = '\0';
dir = FindFirstFile(src, &fdat);
if (dir == INVALID_HANDLE_VALUE) {
run_err("%s: No such file or directory", src);
continue;
}
do {
char *filename;
/*
* Ensure that . and .. are never matched by wildcards,
* but only by deliberate action.
*/
if (!strcmp(fdat.cFileName, ".") ||
!strcmp(fdat.cFileName, "..")) {
/*
* Find*File has returned a special dir. We require
* that _either_ `src' ends in a backslash followed
* by that string, _or_ `src' is precisely that
* string.
*/
int len = strlen(src), dlen = strlen(fdat.cFileName);
if (len == dlen && !strcmp(src, fdat.cFileName)) {
/* ok */ ;
} else if (len > dlen + 1 && src[len - dlen - 1] == '\\' &&
!strcmp(src + len - dlen, fdat.cFileName)) {
/* ok */ ;
} else
continue; /* ignore this one */
}
filename = dupcat(srcpath, fdat.cFileName, NULL);
source(filename);
sfree(filename);
} while (FindNextFile(dir, &fdat));
FindClose(dir);
sfree(srcpath);
}
}
/*
* We will copy files from a remote server to the local machine.
*/
static void tolocal(int argc, char *argv[])
|
<
<
<
<
|
>
|
|
<
<
<
<
<
<
<
<
<
|
<
<
|
<
<
>
>
>
|
<
>
|
|
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
|
|
>
|
|
>
|
<
<
>
>
|
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
|
} else {
*host++ = '\0';
if (*user == '\0')
user = NULL;
}
if (argc == 2) {
if (colon(argv[0]) != NULL)
bump("%s: Remote to remote not supported", argv[0]);
wc_type = test_wildcard(argv[0], 1);
if (wc_type == WCTYPE_NONEXISTENT)
bump("%s: No such file or directory\n", argv[0]);
else if (wc_type == WCTYPE_WILDCARD)
targetshouldbedirectory = 1;
}
cmd = dupprintf("scp%s%s%s%s -t %s",
verbose ? " -v" : "",
recursive ? " -r" : "",
preserve ? " -p" : "",
targetshouldbedirectory ? " -d" : "", targ);
do_cmd(host, user, cmd);
sfree(cmd);
scp_source_setup(targ, targetshouldbedirectory);
for (i = 0; i < argc - 1; i++) {
src = argv[i];
if (colon(src) != NULL) {
tell_user(stderr, "%s: Remote to remote not supported\n", src);
errs++;
continue;
}
wc_type = test_wildcard(src, 1);
if (wc_type == WCTYPE_NONEXISTENT) {
run_err("%s: No such file or directory", src);
continue;
} else if (wc_type == WCTYPE_FILENAME) {
source(src);
continue;
} else {
WildcardMatcher *wc;
char *filename;
wc = begin_wildcard_matching(src);
if (wc == NULL) {
run_err("%s: No such file or directory", src);
continue;
}
while ((filename = wildcard_get_filename(wc)) != NULL) {
source(filename);
sfree(filename);
}
finish_wildcard_matching(wc);
}
}
}
/*
* We will copy files from a remote server to the local machine.
*/
static void tolocal(int argc, char *argv[])
|
| ︙ | | | ︙ | |
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
|
scp_sftp_listdir(src);
} else {
while (ssh_scp_recv(&c, 1) > 0)
tell_char(stdout, c);
}
}
/*
* Initialize the Win$ock driver.
*/
static void init_winsock(void)
{
WORD winsock_ver;
WSADATA wsadata;
winsock_ver = MAKEWORD(1, 1);
if (WSAStartup(winsock_ver, &wsadata))
bump("Unable to initialise WinSock");
if (LOBYTE(wsadata.wVersion) != 1 || HIBYTE(wsadata.wVersion) != 1)
bump("WinSock version is incompatible with 1.1");
}
/*
* Short description of parameters.
*/
static void usage(void)
{
printf("PuTTY Secure Copy client\n");
printf("%s\n", ver);
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
|
scp_sftp_listdir(src);
} else {
while (ssh_scp_recv(&c, 1) > 0)
tell_char(stdout, c);
}
}
/*
* Short description of parameters.
*/
static void usage(void)
{
printf("PuTTY Secure Copy client\n");
printf("%s\n", ver);
|
| ︙ | | | ︙ | |
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
|
vfprintf(stderr, p, ap);
va_end(ap);
fprintf(stderr, "\n try typing just \"pscp\" for help\n");
exit(1);
}
/*
* Main program (no, really?)
*/
int main(int argc, char *argv[])
{
int i;
default_protocol = PROT_TELNET;
flags = FLAG_STDERR | FLAG_SYNCAGENT;
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
ssh_get_line = &console_get_line;
init_winsock();
sk_init();
for (i = 1; i < argc; i++) {
int ret;
if (argv[i][0] != '-')
break;
ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1, &cfg);
|
|
>
|
|
>
>
>
>
<
|
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
|
vfprintf(stderr, p, ap);
va_end(ap);
fprintf(stderr, "\n try typing just \"pscp\" for help\n");
exit(1);
}
/*
* Main program. (Called `psftp_main' because it gets called from
* *sftp.c; bit silly, I know, but it had to be called _something_.)
*/
int psftp_main(int argc, char *argv[])
{
int i;
default_protocol = PROT_TELNET;
flags = FLAG_STDERR
#ifdef FLAG_SYNCAGENT
| FLAG_SYNCAGENT
#endif
;
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
ssh_get_line = &console_get_line;
sk_init();
for (i = 1; i < argc; i++) {
int ret;
if (argv[i][0] != '-')
break;
ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1, &cfg);
|
| ︙ | | | ︙ | |
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
|
} else if (strcmp(argv[i], "-p") == 0) {
preserve = 1;
} else if (strcmp(argv[i], "-q") == 0) {
statistics = 0;
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0) {
usage();
} else if (strcmp(argv[i], "-gui") == 0 && i + 1 < argc) {
gui_hwnd = argv[++i];
gui_mode = 1;
console_batch_mode = TRUE;
} else if (strcmp(argv[i], "-ls") == 0) {
list = 1;
} else if (strcmp(argv[i], "-batch") == 0) {
console_batch_mode = 1;
} else if (strcmp(argv[i], "-unsafe") == 0) {
|
|
|
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
|
} else if (strcmp(argv[i], "-p") == 0) {
preserve = 1;
} else if (strcmp(argv[i], "-q") == 0) {
statistics = 0;
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-?") == 0) {
usage();
} else if (strcmp(argv[i], "-gui") == 0 && i + 1 < argc) {
gui_enable(argv[++i]);
gui_mode = 1;
console_batch_mode = TRUE;
} else if (strcmp(argv[i], "-ls") == 0) {
list = 1;
} else if (strcmp(argv[i], "-batch") == 0) {
console_batch_mode = 1;
} else if (strcmp(argv[i], "-unsafe") == 0) {
|
| ︙ | | | ︙ | |
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
|
}
if (back != NULL && back->socket(backhandle) != NULL) {
char ch;
back->special(backhandle, TS_EOF);
ssh_scp_recv(&ch, 1);
}
WSACleanup();
random_save_seed();
/* GUI Adaptation - August 2000 */
if (gui_mode) {
unsigned int msg_id = WM_RET_ERR_CNT;
if (list)
msg_id = WM_LS_RET_ERR_CNT;
while (!PostMessage
((HWND) atoi(gui_hwnd), msg_id, (WPARAM) errs,
0 /*lParam */ ))SleepEx(1000, TRUE);
}
return (errs == 0 ? 0 : 1);
}
/* end */
|
<
<
|
<
|
<
<
<
<
|
|
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
|
}
if (back != NULL && back->socket(backhandle) != NULL) {
char ch;
back->special(backhandle, TS_EOF);
ssh_scp_recv(&ch, 1);
}
random_save_seed();
if (gui_mode)
gui_send_errcount(list, errs);
return (errs == 0 ? 0 : 1);
}
/* end */
|