2 * scp.c - Scp (Secure Copy) client for PuTTY.
3 * Joris van Rantwijk, Simon Tatham
5 * This is mainly based on ssh-1.2.26/scp.c by Timo Rinne & Tatu Ylonen.
6 * They, in turn, used stuff from BSD rcp.
8 * Adaptations to enable connecting a GUI by L. Gunnarsson - Sept 2000
23 /* GUI Adaptation - Sept 2000 */
27 #define PUTTY_DO_GLOBALS
30 #define TIME_POSIX_TO_WIN(t, ft) (*(LONGLONG*)&(ft) = \
31 ((LONGLONG) (t) + (LONGLONG) 11644473600) * (LONGLONG) 10000000)
32 #define TIME_WIN_TO_POSIX(ft, t) ((t) = (unsigned long) \
33 ((*(LONGLONG*)&(ft)) / (LONGLONG) 10000000 - (LONGLONG) 11644473600))
35 /* GUI Adaptation - Sept 2000 */
36 #define WM_APP_BASE 0x8000
37 #define WM_STD_OUT_CHAR ( WM_APP_BASE+400 )
38 #define WM_STD_ERR_CHAR ( WM_APP_BASE+401 )
39 #define WM_STATS_CHAR ( WM_APP_BASE+402 )
40 #define WM_STATS_SIZE ( WM_APP_BASE+403 )
41 #define WM_STATS_PERCENT ( WM_APP_BASE+404 )
42 #define WM_STATS_ELAPSED ( WM_APP_BASE+405 )
43 #define WM_RET_ERR_CNT ( WM_APP_BASE+406 )
44 #define WM_LS_RET_ERR_CNT ( WM_APP_BASE+407 )
46 static int verbose
= 0;
47 static int recursive
= 0;
48 static int preserve
= 0;
49 static int targetshouldbedirectory
= 0;
50 static int statistics
= 1;
51 static int portnumber
= 0;
52 static char *password
= NULL
;
54 static int connection_open
= 0;
55 /* GUI Adaptation - Sept 2000 */
56 #define NAME_STR_MAX 2048
57 static char statname
[NAME_STR_MAX
+1];
58 static unsigned long statsize
= 0;
59 static int statperct
= 0;
60 static time_t statelapsed
= 0;
61 static int gui_mode
= 0;
62 static char *gui_hwnd
= NULL
;
64 static void source(char *src
);
65 static void rsource(char *src
);
66 static void sink(char *targ
);
67 /* GUI Adaptation - Sept 2000 */
68 static void tell_char(FILE *stream
, char c
);
69 static void tell_str(FILE *stream
, char *str
);
70 static void tell_user(FILE *stream
, char *fmt
, ...);
71 static void send_char_msg(unsigned int msg_id
, char c
);
72 static void send_str_msg(unsigned int msg_id
, char *str
);
73 static void gui_update_stats(char *name
, unsigned long size
, int percentage
, time_t elapsed
);
76 * These functions are needed to link with other modules, but
77 * (should) never get called.
79 void begin_session(void) { }
80 void write_clip (void *data
, int len
) { }
81 void term_deselect(void) { }
83 /* GUI Adaptation - Sept 2000 */
84 void send_msg(HWND h
, UINT message
, WPARAM wParam
)
86 while (!PostMessage( h
, message
, wParam
, 0))
90 void tell_char(FILE *stream
, char c
)
96 unsigned int msg_id
= WM_STD_OUT_CHAR
;
97 if (stream
= stderr
) msg_id
= WM_STD_ERR_CHAR
;
98 send_msg( (HWND
)atoi(gui_hwnd
), msg_id
, (WPARAM
)c
);
102 void tell_str(FILE *stream
, char *str
)
106 for( i
= 0; i
< strlen(str
); ++i
)
107 tell_char(stream
, str
[i
]);
110 void tell_user(FILE *stream
, char *fmt
, ...)
112 char str
[0x100]; /* Make the size big enough */
115 vsprintf(str
, fmt
, ap
);
118 tell_str(stream
, str
);
121 void gui_update_stats(char *name
, unsigned long size
, int percentage
, time_t elapsed
)
125 if (strcmp(name
,statname
) != 0)
127 for( i
= 0; i
< strlen(name
); ++i
)
128 send_msg( (HWND
)atoi(gui_hwnd
), WM_STATS_CHAR
, (WPARAM
)name
[i
]);
129 send_msg( (HWND
)atoi(gui_hwnd
), WM_STATS_CHAR
, (WPARAM
)'\n' );
130 strcpy(statname
,name
);
132 if (statsize
!= size
)
134 send_msg( (HWND
)atoi(gui_hwnd
), WM_STATS_SIZE
, (WPARAM
)size
);
137 if (statelapsed
!= elapsed
)
139 send_msg( (HWND
)atoi(gui_hwnd
), WM_STATS_ELAPSED
, (WPARAM
)elapsed
);
140 statelapsed
= elapsed
;
142 if (statperct
!= percentage
)
144 send_msg( (HWND
)atoi(gui_hwnd
), WM_STATS_PERCENT
, (WPARAM
)percentage
);
145 statperct
= percentage
;
150 * Print an error message and perform a fatal exit.
152 void fatalbox(char *fmt
, ...)
154 char str
[0x100]; /* Make the size big enough */
157 strcpy(str
, "Fatal:");
158 vsprintf(str
+strlen(str
), fmt
, ap
);
161 tell_str(stderr
, str
);
165 void connection_fatal(char *fmt
, ...)
167 char str
[0x100]; /* Make the size big enough */
170 strcpy(str
, "Fatal:");
171 vsprintf(str
+strlen(str
), fmt
, ap
);
174 tell_str(stderr
, str
);
180 * Receive a block of data from the SSH link. Block until all data
183 * To do this, we repeatedly call the SSH protocol module, with our
184 * own trap in term_out() to catch the data that comes back. We do
185 * this until we have enough data.
187 static unsigned char *outptr
; /* where to put the data */
188 static unsigned outlen
; /* how much data required */
189 static unsigned char *pending
= NULL
; /* any spare data */
190 static unsigned pendlen
=0, pendsize
=0; /* length and phys. size of buffer */
191 void term_out(void) {
193 * Here we must deal with a block of data, in `inbuf', size
196 unsigned char *p
= inbuf
;
197 unsigned len
= inbuf_head
;
202 * If this is before the real session begins, just return.
208 unsigned used
= outlen
;
209 if (used
> len
) used
= len
;
210 memcpy(outptr
, p
, used
);
211 outptr
+= used
; outlen
-= used
;
212 p
+= used
; len
-= used
;
216 if (pendsize
< pendlen
+ len
) {
217 pendsize
= pendlen
+ len
+ 4096;
218 pending
= (pending ?
realloc(pending
, pendsize
) :
221 fatalbox("Out of memory");
223 memcpy(pending
+pendlen
, p
, len
);
227 static int ssh_scp_recv(unsigned char *buf
, int len
) {
234 * See if the pending-input block contains some of what we
238 unsigned pendused
= pendlen
;
239 if (pendused
> outlen
)
241 memcpy(outptr
, pending
, pendused
);
242 memmove(pending
, pending
+pendused
, pendlen
-pendused
);
258 if (s
== INVALID_SOCKET
) {
259 connection_open
= FALSE
;
264 if (select(1, &readfds
, NULL
, NULL
, NULL
) < 0)
266 back
->msg(0, FD_READ
);
274 * Loop through the ssh connection and authentication process.
276 static void ssh_scp_init(void) {
280 if (s
== INVALID_SOCKET
)
282 while (!back
->sendok()) {
286 if (select(1, &readfds
, NULL
, NULL
, NULL
) < 0)
288 back
->msg(0, FD_READ
);
294 * Print an error message and exit after closing the SSH link.
296 static void bump(char *fmt
, ...)
298 char str
[0x100]; /* Make the size big enough */
301 strcpy(str
, "Fatal:");
302 vsprintf(str
+strlen(str
), fmt
, ap
);
305 tell_str(stderr
, str
);
307 if (connection_open
) {
309 back
->special(TS_EOF
);
310 ssh_scp_recv(&ch
, 1);
315 static int get_password(const char *prompt
, char *str
, int maxlen
)
321 static int tried_once
= 0;
326 strncpy(str
, password
, maxlen
);
327 str
[maxlen
-1] = '\0';
333 /* GUI Adaptation - Sept 2000 */
335 if (maxlen
>0) str
[0] = '\0';
337 hin
= GetStdHandle(STD_INPUT_HANDLE
);
338 hout
= GetStdHandle(STD_OUTPUT_HANDLE
);
339 if (hin
== INVALID_HANDLE_VALUE
|| hout
== INVALID_HANDLE_VALUE
)
340 bump("Cannot get standard input/output handles");
342 GetConsoleMode(hin
, &savemode
);
343 SetConsoleMode(hin
, (savemode
& (~ENABLE_ECHO_INPUT
)) |
344 ENABLE_PROCESSED_INPUT
| ENABLE_LINE_INPUT
);
346 WriteFile(hout
, prompt
, strlen(prompt
), &i
, NULL
);
347 ReadFile(hin
, str
, maxlen
-1, &i
, NULL
);
349 SetConsoleMode(hin
, savemode
);
351 if ((int)i
> maxlen
) i
= maxlen
-1; else i
= i
- 2;
354 WriteFile(hout
, "\r\n", 2, &i
, NULL
);
361 * Open an SSH connection to user@host and execute cmd.
363 static void do_cmd(char *host
, char *user
, char *cmd
)
365 char *err
, *realhost
;
367 if (host
== NULL
|| host
[0] == '\0')
368 bump("Empty host name");
370 /* Try to load settings for this host */
372 if (cfg
.host
[0] == '\0') {
373 /* No settings for this host; use defaults */
374 strncpy(cfg
.host
, host
, sizeof(cfg
.host
)-1);
375 cfg
.host
[sizeof(cfg
.host
)-1] = '\0';
380 if (user
!= NULL
&& user
[0] != '\0') {
381 strncpy(cfg
.username
, user
, sizeof(cfg
.username
)-1);
382 cfg
.username
[sizeof(cfg
.username
)-1] = '\0';
383 } else if (cfg
.username
[0] == '\0') {
384 bump("Empty user name");
387 if (cfg
.protocol
!= PROT_SSH
)
391 cfg
.port
= portnumber
;
393 strncpy(cfg
.remote_cmd
, cmd
, sizeof(cfg
.remote_cmd
));
394 cfg
.remote_cmd
[sizeof(cfg
.remote_cmd
)-1] = '\0';
399 err
= back
->init(NULL
, cfg
.host
, cfg
.port
, &realhost
);
401 bump("ssh_init: %s", err
);
403 if (verbose
&& realhost
!= NULL
)
404 tell_user(stderr
, "Connected to %s\n", realhost
);
410 * Update statistic information about current file.
412 static void print_stats(char *name
, unsigned long size
, unsigned long done
,
413 time_t start
, time_t now
)
420 /* GUI Adaptation - Sept 2000 */
422 gui_update_stats(name
, size
, ((done
*100) / size
), now
-start
);
425 ratebs
= (float) done
/ (now
- start
);
427 ratebs
= (float) done
;
432 eta
= (unsigned long) ((size
- done
) / ratebs
);
433 sprintf(etastr
, "%02ld:%02ld:%02ld",
434 eta
/ 3600, (eta
% 3600) / 60, eta
% 60);
436 pct
= (int) (100.0 * (float) done
/ size
);
438 printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%",
439 name
, done
/ 1024, ratebs
/ 1024.0,
448 * Find a colon in str and return a pointer to the colon.
449 * This is used to separate hostname from filename.
451 static char * colon(char *str
)
453 /* We ignore a leading colon, since the hostname cannot be
454 empty. We also ignore a colon as second character because
455 of filenames like f:myfile.txt. */
456 if (str
[0] == '\0' ||
460 while (*str
!= '\0' &&
472 * Wait for a response from the other side.
473 * Return 0 if ok, -1 if error.
475 static int response(void)
477 char ch
, resp
, rbuf
[2048];
480 if (ssh_scp_recv(&resp
, 1) <= 0)
481 bump("Lost connection");
491 case 2: /* fatal error */
493 if (ssh_scp_recv(&ch
, 1) <= 0)
494 bump("Protocol error: Lost connection");
496 } while (p
< sizeof(rbuf
) && ch
!= '\n');
499 tell_user(stderr
, "%s\n", rbuf
);
508 * Send an error message to the other side and to the screen.
509 * Increment error counter.
511 static void run_err(const char *fmt
, ...)
517 strcpy(str
, "\01scp: ");
518 vsprintf(str
+strlen(str
), fmt
, ap
);
520 back
->send(str
, strlen(str
));
521 tell_user(stderr
, "%s",str
);
526 * Execute the source part of the SCP protocol.
528 static void source(char *src
)
536 unsigned long stat_bytes
;
537 time_t stat_starttime
, stat_lasttime
;
539 attr
= GetFileAttributes(src
);
540 if (attr
== (DWORD
)-1) {
541 run_err("%s: No such file or directory", src
);
545 if ((attr
& FILE_ATTRIBUTE_DIRECTORY
) != 0) {
548 * Avoid . and .. directories.
551 p
= strrchr(src
, '/');
553 p
= strrchr(src
, '\\');
558 if (!strcmp(p
, ".") || !strcmp(p
, ".."))
563 run_err("%s: not a regular file", src
);
568 if ((last
= strrchr(src
, '/')) == NULL
)
572 if (strrchr(last
, '\\') != NULL
)
573 last
= strrchr(last
, '\\') + 1;
574 if (last
== src
&& strchr(src
, ':') != NULL
)
575 last
= strchr(src
, ':') + 1;
577 f
= CreateFile(src
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
578 OPEN_EXISTING
, 0, 0);
579 if (f
== INVALID_HANDLE_VALUE
) {
580 run_err("%s: Cannot open file", src
);
585 FILETIME actime
, wrtime
;
586 unsigned long mtime
, atime
;
587 GetFileTime(f
, NULL
, &actime
, &wrtime
);
588 TIME_WIN_TO_POSIX(actime
, atime
);
589 TIME_WIN_TO_POSIX(wrtime
, mtime
);
590 sprintf(buf
, "T%lu 0 %lu 0\n", mtime
, atime
);
591 back
->send(buf
, strlen(buf
));
596 size
= GetFileSize(f
, NULL
);
597 sprintf(buf
, "C0644 %lu %s\n", size
, last
);
599 tell_user(stderr
, "Sending file modes: %s", buf
);
600 back
->send(buf
, strlen(buf
));
606 stat_starttime
= time(NULL
);
610 for (i
= 0; i
< size
; i
+= 4096) {
613 if (i
+ k
> size
) k
= size
- i
;
614 if (! ReadFile(f
, transbuf
, k
, &j
, NULL
) || j
!= k
) {
615 if (statistics
) printf("\n");
616 bump("%s: Read error", src
);
618 back
->send(transbuf
, k
);
621 if (time(NULL
) != stat_lasttime
||
623 stat_lasttime
= time(NULL
);
624 print_stats(last
, size
, stat_bytes
,
625 stat_starttime
, stat_lasttime
);
636 * Recursively send the contents of a directory.
638 static void rsource(char *src
)
643 WIN32_FIND_DATA fdat
;
646 if ((last
= strrchr(src
, '/')) == NULL
)
650 if (strrchr(last
, '\\') != NULL
)
651 last
= strrchr(last
, '\\') + 1;
652 if (last
== src
&& strchr(src
, ':') != NULL
)
653 last
= strchr(src
, ':') + 1;
655 /* maybe send filetime */
657 sprintf(buf
, "D0755 0 %s\n", last
);
659 tell_user(stderr
, "Entering directory: %s", buf
);
660 back
->send(buf
, strlen(buf
));
664 sprintf(buf
, "%s/*", src
);
665 dir
= FindFirstFile(buf
, &fdat
);
666 ok
= (dir
!= INVALID_HANDLE_VALUE
);
668 if (strcmp(fdat
.cFileName
, ".") == 0 ||
669 strcmp(fdat
.cFileName
, "..") == 0) {
670 } else if (strlen(src
) + 1 + strlen(fdat
.cFileName
) >=
672 run_err("%s/%s: Name too long", src
, fdat
.cFileName
);
674 sprintf(buf
, "%s/%s", src
, fdat
.cFileName
);
677 ok
= FindNextFile(dir
, &fdat
);
682 back
->send(buf
, strlen(buf
));
687 * Execute the sink part of the SCP protocol.
689 static void sink(char *targ
)
699 unsigned long mtime
, atime
;
701 unsigned long size
, i
;
703 unsigned long stat_bytes
;
704 time_t stat_starttime
, stat_lasttime
;
707 attr
= GetFileAttributes(targ
);
708 if (attr
!= (DWORD
)-1 && (attr
& FILE_ATTRIBUTE_DIRECTORY
) != 0)
711 if (targetshouldbedirectory
&& !targisdir
)
712 bump("%s: Not a directory", targ
);
718 if (ssh_scp_recv(&ch
, 1) <= 0)
721 bump("Protocol error: Unexpected newline");
725 if (ssh_scp_recv(&ch
, 1) <= 0)
726 bump("Lost connection");
728 } while (i
< sizeof(buf
) && ch
!= '\n');
731 case '\01': /* error */
732 tell_user(stderr
, "%s\n", buf
+1);
735 case '\02': /* fatal error */
741 if (sscanf(buf
, "T%ld %*d %ld %*d",
742 &mtime
, &atime
) == 2) {
747 bump("Protocol error: Illegal time format");
752 bump("Protocol error: Expected control record");
755 if (sscanf(buf
+1, "%u %lu %[^\n]", &mode
, &size
, namebuf
) != 3)
756 bump("Protocol error: Illegal file descriptor format");
765 strcpy(namebuf
, targ
);
767 attr
= GetFileAttributes(namebuf
);
768 exists
= (attr
!= (DWORD
)-1);
771 if (exists
&& (attr
& FILE_ATTRIBUTE_DIRECTORY
) == 0) {
772 run_err("%s: Not a directory", namebuf
);
776 if (! CreateDirectory(namebuf
, NULL
)) {
777 run_err("%s: Cannot create directory",
783 /* can we set the timestamp for directories ? */
787 f
= CreateFile(namebuf
, GENERIC_WRITE
, 0, NULL
,
788 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
789 if (f
== INVALID_HANDLE_VALUE
) {
790 run_err("%s: Cannot create file", namebuf
);
798 stat_starttime
= time(NULL
);
800 if ((stat_name
= strrchr(namebuf
, '/')) == NULL
)
804 if (strrchr(stat_name
, '\\') != NULL
)
805 stat_name
= strrchr(stat_name
, '\\') + 1;
808 for (i
= 0; i
< size
; i
+= 4096) {
811 if (i
+ k
> size
) k
= size
- i
;
812 if (ssh_scp_recv(transbuf
, k
) == 0)
813 bump("Lost connection");
814 if (wrerror
) continue;
815 if (! WriteFile(f
, transbuf
, k
, &j
, NULL
) || j
!= k
) {
818 printf("\r%-25.25s | %50s\n",
820 "Write error.. waiting for end of file");
825 if (time(NULL
) > stat_lasttime
||
827 stat_lasttime
= time(NULL
);
828 print_stats(stat_name
, size
, stat_bytes
,
829 stat_starttime
, stat_lasttime
);
836 FILETIME actime
, wrtime
;
837 TIME_POSIX_TO_WIN(atime
, actime
);
838 TIME_POSIX_TO_WIN(mtime
, wrtime
);
839 SetFileTime(f
, NULL
, &actime
, &wrtime
);
844 run_err("%s: Write error", namebuf
);
852 * We will copy local files to a remote server.
854 static void toremote(int argc
, char *argv
[])
856 char *src
, *targ
, *host
, *user
;
862 /* Separate host from filename */
866 bump("targ == NULL in toremote()");
870 /* Substitute "." for emtpy target */
872 /* Separate host and username */
874 host
= strrchr(host
, '@');
885 /* Find out if the source filespec covers multiple files
886 if so, we should set the targetshouldbedirectory flag */
888 WIN32_FIND_DATA fdat
;
889 if (colon(argv
[0]) != NULL
)
890 bump("%s: Remote to remote not supported", argv
[0]);
891 fh
= FindFirstFile(argv
[0], &fdat
);
892 if (fh
== INVALID_HANDLE_VALUE
)
893 bump("%s: No such file or directory\n", argv
[0]);
894 if (FindNextFile(fh
, &fdat
))
895 targetshouldbedirectory
= 1;
899 cmd
= smalloc(strlen(targ
) + 100);
900 sprintf(cmd
, "scp%s%s%s%s -t %s",
901 verbose ?
" -v" : "",
902 recursive ?
" -r" : "",
903 preserve ?
" -p" : "",
904 targetshouldbedirectory ?
" -d" : "",
906 do_cmd(host
, user
, cmd
);
911 for (i
= 0; i
< argc
- 1; i
++) {
913 WIN32_FIND_DATA fdat
;
915 if (colon(src
) != NULL
) {
916 tell_user(stderr
, "%s: Remote to remote not supported\n", src
);
920 dir
= FindFirstFile(src
, &fdat
);
921 if (dir
== INVALID_HANDLE_VALUE
) {
922 run_err("%s: No such file or directory", src
);
928 if (strlen(src
) + strlen(fdat
.cFileName
) >=
930 tell_user(stderr
, "%s: Name too long", src
);
933 strcpy(namebuf
, src
);
934 if ((last
= strrchr(namebuf
, '/')) == NULL
)
938 if (strrchr(last
, '\\') != NULL
)
939 last
= strrchr(last
, '\\') + 1;
940 if (last
== namebuf
&& strrchr(namebuf
, ':') != NULL
)
941 last
= strchr(namebuf
, ':') + 1;
942 strcpy(last
, fdat
.cFileName
);
944 } while (FindNextFile(dir
, &fdat
));
950 * We will copy files from a remote server to the local machine.
952 static void tolocal(int argc
, char *argv
[])
954 char *src
, *targ
, *host
, *user
;
958 bump("More than one remote source not supported");
963 /* Separate host from filename */
967 bump("Local to local copy not supported");
971 /* Substitute "." for empty filename */
973 /* Separate username and hostname */
975 host
= strrchr(host
, '@');
985 cmd
= smalloc(strlen(src
) + 100);
986 sprintf(cmd
, "scp%s%s%s%s -f %s",
987 verbose ?
" -v" : "",
988 recursive ?
" -r" : "",
989 preserve ?
" -p" : "",
990 targetshouldbedirectory ?
" -d" : "",
992 do_cmd(host
, user
, cmd
);
999 * We will issue a list command to get a remote directory.
1001 static void get_dir_list(int argc
, char *argv
[])
1003 char *src
, *host
, *user
;
1009 /* Separate host from filename */
1013 bump("Local to local copy not supported");
1017 /* Substitute "." for empty filename */
1019 /* Separate username and hostname */
1021 host
= strrchr(host
, '@');
1031 cmd
= smalloc(4*strlen(src
) + 100);
1032 strcpy(cmd
, "ls -la '");
1033 p
= cmd
+ strlen(cmd
);
1034 for (q
= src
; *q
; q
++) {
1036 *p
++ = '\''; *p
++ = '\\'; *p
++ = '\''; *p
++ = '\'';
1044 do_cmd(host
, user
, cmd
);
1047 while (ssh_scp_recv(&c
, 1) > 0)
1048 tell_char(stdout
, c
);
1052 * Initialize the Win$ock driver.
1054 static void init_winsock(void)
1059 winsock_ver
= MAKEWORD(1, 1);
1060 if (WSAStartup(winsock_ver
, &wsadata
))
1061 bump("Unable to initialise WinSock");
1062 if (LOBYTE(wsadata
.wVersion
) != 1 ||
1063 HIBYTE(wsadata
.wVersion
) != 1)
1064 bump("WinSock version is incompatible with 1.1");
1068 * Short description of parameters.
1070 static void usage(void)
1072 printf("PuTTY Secure Copy client\n");
1073 printf("%s\n", ver
);
1074 printf("Usage: pscp [options] [user@]host:source target\n");
1075 printf(" pscp [options] source [source...] [user@]host:target\n");
1076 printf(" pscp [options] -ls user@host:filespec\n");
1077 printf("Options:\n");
1078 printf(" -p preserve file attributes\n");
1079 printf(" -q quiet, don't show statistics\n");
1080 printf(" -r copy directories recursively\n");
1081 printf(" -v show verbose messages\n");
1082 printf(" -P port connect to specified port\n");
1083 printf(" -pw passw login with specified password\n");
1084 /* GUI Adaptation - Sept 2000 */
1085 printf(" -gui hWnd GUI mode with the windows handle for receiving messages\n");
1090 * Main program (no, really?)
1092 int main(int argc
, char *argv
[])
1097 default_protocol
= PROT_TELNET
;
1099 flags
= FLAG_STDERR
;
1100 ssh_get_password
= &get_password
;
1103 for (i
= 1; i
< argc
; i
++) {
1104 if (argv
[i
][0] != '-')
1106 if (strcmp(argv
[i
], "-v") == 0)
1107 verbose
= 1, flags
|= FLAG_VERBOSE
;
1108 else if (strcmp(argv
[i
], "-r") == 0)
1110 else if (strcmp(argv
[i
], "-p") == 0)
1112 else if (strcmp(argv
[i
], "-q") == 0)
1114 else if (strcmp(argv
[i
], "-h") == 0 ||
1115 strcmp(argv
[i
], "-?") == 0)
1117 else if (strcmp(argv
[i
], "-P") == 0 && i
+1 < argc
)
1118 portnumber
= atoi(argv
[++i
]);
1119 else if (strcmp(argv
[i
], "-pw") == 0 && i
+1 < argc
)
1120 password
= argv
[++i
];
1121 else if (strcmp(argv
[i
], "-gui") == 0 && i
+1 < argc
) {
1122 gui_hwnd
= argv
[++i
];
1124 } else if (strcmp(argv
[i
], "-ls") == 0)
1126 else if (strcmp(argv
[i
], "--") == 0)
1137 get_dir_list(argc
, argv
);
1144 targetshouldbedirectory
= 1;
1146 if (colon(argv
[argc
-1]) != NULL
)
1147 toremote(argc
, argv
);
1149 tolocal(argc
, argv
);
1152 if (connection_open
) {
1154 back
->special(TS_EOF
);
1155 ssh_scp_recv(&ch
, 1);
1160 /* GUI Adaptation - August 2000 */
1162 unsigned int msg_id
= WM_RET_ERR_CNT
;
1163 if (list
) msg_id
= WM_LS_RET_ERR_CNT
;
1164 while (!PostMessage( (HWND
)atoi(gui_hwnd
), msg_id
, (WPARAM
)errs
, 0/*lParam*/ ) )
1167 return (errs
== 0 ?
0 : 1);