2 * Copyright (c) 1985, 1989 Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 * FTP User Program -- Command Routines.
24 #include "pathnames.h"
27 static char sccsid
[] = "@(#)cmds.c 5.18 (Berkeley) 4/20/89";
32 static const char *remglob(const char *argv
[], int doswitch
);
34 extern off_t restart_point
;
35 extern char reply_string
[];
39 const char *dotrans(const char *name
);
40 const char *domap(const char *name
);
43 extern char *hostname
;
46 * Connect to peer server and
47 * auto-login, if possible.
49 void setpeer(int argc
, const char *argv
[])
54 printf("Already connected to %s, use close first.\n",
56 (void) fflush(stdout
);
61 (void) strcat(line
, " ");
63 (void) fflush(stdout
);
64 (void) gets(&line
[strlen(line
)]);
70 printf("usage: %s host-name [port]\n", argv
[0]);
71 (void) fflush(stdout
);
76 portnum
= atoi(argv
[2]);
78 printf("%s: bad port number-- %s\n", argv
[1], argv
[2]);
79 printf ("usage: %s host-name [port]\n", argv
[0]);
80 (void) fflush(stdout
);
84 portnum
= htons(portnum
);
86 host
= hookup(argv
[1], portnum
);
88 #if defined(unix) && NBBY == 8
93 (void) login(argv
[1]);
95 #if defined(unix) && NBBY == 8
97 * this ifdef is to keep someone form "porting" this to an incompatible
98 * system and not checking this out. This way they have to think about it.
104 if (command("SYST") == COMPLETE
&& overbose
) {
105 register char *cp
, c
;
106 cp
= index(reply_string
+4, ' ');
108 cp
= index(reply_string
+4, '\r');
116 printf("Remote system type is %s.\n",
121 if (!strncmp(reply_string
, "215 UNIX Type: L8", 17)) {
123 /* allbinary = 1; this violates the RFC */
125 printf("Using %s mode to transfer files.\n",
127 } else if (overbose
&&
128 !strncmp(reply_string
, "215 TOPS20", 10)) {
130 "Remember to set tenex mode when transfering binary files from this machine.\n");
135 (void) fflush(stdout
);
144 { "ascii", "A", TYPE_A
, 0 },
145 { "binary", "I", TYPE_I
, 0 },
146 { "image", "I", TYPE_I
, 0 },
147 { "ebcdic", "E", TYPE_E
, 0 },
148 { "tenex", "L", TYPE_L
, bytename
},
155 void settype(int argc
, const char *argv
[])
157 register struct types
*p
;
163 printf("usage: %s [", argv
[0]);
165 for (p
= types
; p
->t_name
; p
++) {
166 printf("%s%s", sep
, p
->t_name
);
171 (void) fflush(stdout
);
176 printf("Using %s mode to transfer files.\n", typename
);
177 (void) fflush(stdout
);
181 for (p
= types
; p
->t_name
; p
++)
182 if (strcmp(argv
[1], p
->t_name
) == 0)
184 if (p
->t_name
== 0) {
185 printf("%s: unknown mode\n", argv
[1]);
186 (void) fflush(stdout
);
190 if ((p
->t_arg
!= NULL
) && (*(p
->t_arg
) != '\0'))
191 comret
= command ("TYPE %s %s", p
->t_mode
, p
->t_arg
);
193 comret
= command("TYPE %s", p
->t_mode
);
194 if (comret
== COMPLETE
) {
195 (void) strcpy(typename
, p
->t_name
);
200 const char *stype
[] = {
207 * Set binary transfer type.
210 void setbinary(int argc
, const char *argv
[])
217 * Set ascii transfer type.
220 void setascii(int argc
, const char *argv
[])
227 * Set tenex transfer type.
230 void settenex(int argc
, const char *argv
[])
237 * Set ebcdic transfer type.
247 * Set file transfer mode.
251 void fsetmode(int argc
, const char *argv
[])
254 printf("We only support %s mode, sorry.\n", modename
);
255 (void) fflush(stdout
);
261 * Set file transfer format.
264 void setform(int argc
, const char *argv
[])
267 printf("We only support %s format, sorry.\n", formname
);
268 (void) fflush(stdout
);
273 * Set file transfer structure.
276 void setstruct(int argc
, const char *argv
[])
279 printf("We only support %s structure, sorry.\n", structname
);
280 (void) fflush(stdout
);
285 * Send a single file.
287 void put(int argc
, const char *argv
[])
291 const char *oldargv1
, *oldargv2
;
299 (void) strcat(line
, " ");
300 printf("(local-file) ");
301 (void) fflush(stdout
);
302 (void) gets(&line
[strlen(line
)]);
309 printf("usage:%s local-file remote-file\n", argv
[0]);
310 (void) fflush(stdout
);
315 (void) strcat(line
, " ");
316 printf("(remote-file) ");
317 (void) fflush(stdout
);
318 (void) gets(&line
[strlen(line
)]);
327 if (!globulize(&argv
[1])) {
332 * If "globulize" modifies argv[1], and argv[2] is a copy of
333 * the old argv[1], make it a copy of the new argv[1].
335 if (argv
[1] != oldargv1
&& argv
[2] == oldargv1
) {
338 cmd
= (argv
[0][0] == 'a') ? "APPE" : ((sunique
) ? "STOU" : "STOR");
340 argv
[2] = dotrans(argv
[2]);
342 if (loc
&& mapflag
) {
343 argv
[2] = domap(argv
[2]);
345 sendrequest(cmd
, argv
[1], argv
[2],
346 argv
[1] != oldargv1
|| argv
[2] != oldargv2
);
350 * Send multiple files.
352 void mput(int argc
, const char *argv
[])
356 extern jmp_buf jabort
;
360 (void) strcat(line
, " ");
361 printf("(local-files) ");
362 (void) fflush(stdout
);
363 (void) gets(&line
[strlen(line
)]);
369 printf("usage:%s local-files\n", argv
[0]);
370 (void) fflush(stdout
);
376 // oldintr = signal(SIGINT, mabort);
377 (void) setjmp(jabort
);
380 char *tp2
, tmpbuf
[MAXPATHLEN
];
382 while ((cp
= remglob(argv
,0)) != NULL
) {
387 if (mflag
&& confirm(argv
[0], cp
)) {
390 while (*tp
&& !islower(*tp
)) {
396 while ((*tp2
= *tp
)) {
398 *tp2
= 'a' + *tp2
- 'A';
412 sendrequest((sunique
) ? "STOU" : "STOR",
413 cp
, tp
, cp
!= tp
|| !interactive
);
414 if (!mflag
&& fromatty
) {
415 ointer
= interactive
;
417 if (confirm("Continue with","mput")) {
420 interactive
= ointer
;
424 // (void) signal(SIGINT, oldintr);
428 for (i
= 1; i
< argc
; i
++) {
429 register char **cpp
, **gargs
;
432 if (mflag
&& confirm(argv
[0], argv
[i
])) {
433 tp
= (ntflag
) ? dotrans(argv
[i
]) : argv
[i
];
434 tp
= (mapflag
) ? domap(tp
) : tp
;
435 sendrequest((sunique
) ? "STOU" : "STOR",
436 argv
[i
], tp
, tp
!= argv
[i
] || !interactive
);
437 if (!mflag
&& fromatty
) {
438 ointer
= interactive
;
440 if (confirm("Continue with","mput")) {
443 interactive
= ointer
;
448 gargs
= glob(argv
[i
]);
449 if (globerr
!= NULL
) {
450 printf("%s\n", globerr
);
451 (void) fflush(stdout
);
458 for (cpp
= gargs
; cpp
&& *cpp
!= NULL
; cpp
++) {
459 if (mflag
&& confirm(argv
[0], *cpp
)) {
460 tp
= (ntflag
) ? dotrans(*cpp
) : *cpp
;
461 tp
= (mapflag
) ? domap(tp
) : tp
;
462 sendrequest((sunique
) ? "STOU" : "STOR",
463 *cpp
, tp
, *cpp
!= tp
|| !interactive
);
464 if (!mflag
&& fromatty
) {
465 ointer
= interactive
;
467 if (confirm("Continue with","mput")) {
470 interactive
= ointer
;
479 // (void) signal(SIGINT, oldintr);
483 void reget(int argc
, const char *argv
[])
485 (void) getit(argc
, argv
, 1, "r+w");
488 void get(int argc
, const char *argv
[])
490 (void) getit(argc
, argv
, 0, restart_point
? "r+w" : "w" );
496 int getit(int argc
, const char *argv
[], int restartit
, const char *mode
)
499 const char *oldargv1
, *oldargv2
;
507 (void) strcat(line
, " ");
508 printf("(remote-file) ");
509 (void) fflush(stdout
);
510 (void) gets(&line
[strlen(line
)]);
517 printf("usage: %s remote-file [ local-file ]\n", argv
[0]);
518 (void) fflush(stdout
);
523 (void) strcat(line
, " ");
524 printf("(local-file) ");
525 (void) fflush(stdout
);
526 (void) gets(&line
[strlen(line
)]);
535 if (!globulize(&argv
[2])) {
540 const char *tp
= argv
[1];
541 char *tp2
, tmpbuf
[MAXPATHLEN
];
543 while (*tp
&& !islower(*tp
)) {
549 while ((*tp2
= *tp
)) {
551 *tp2
= 'a' + *tp2
- 'A';
560 argv
[2] = dotrans(argv
[2]);
562 argv
[2] = domap(argv
[2]);
567 ret
= stat(argv
[2], &stbuf
);
568 if (restartit
== 1) {
573 restart_point
= stbuf
.st_size
;
581 if (command("MDTM %s", argv
[1]) == COMPLETE
) {
582 int yy
, mo
, day
, hour
, min
, sec
;
586 "%*s %04d%02d%02d%02d%02d%02d",
587 &yy
, &mo
, &day
, &hour
, &min
, &sec
);
588 tm
= gmtime(&stbuf
.st_mtime
);
590 if (tm
->tm_year
> yy
%100)
592 else if (tm
->tm_year
== yy
%100) {
595 } else if (tm
->tm_mon
== mo
) {
596 if (tm
->tm_mday
> day
)
598 } else if (tm
->tm_mday
== day
) {
599 if (tm
->tm_hour
> hour
)
601 } else if (tm
->tm_hour
== hour
) {
602 if (tm
->tm_min
> min
)
604 } else if (tm
->tm_min
== min
) {
605 if (tm
->tm_sec
> sec
)
609 printf("%s\n", reply_string
);
610 (void) fflush(stdout
);
618 recvrequest("RETR", argv
[2], argv
[1], mode
,
619 argv
[1] != oldargv1
|| argv
[2] != oldargv2
);
629 extern jmp_buf jabort
;
632 (void) fflush(stdout
);
633 if (mflag
&& fromatty
) {
634 ointer
= interactive
;
636 if (confirm("Continue with", mname
)) {
637 interactive
= ointer
;
640 interactive
= ointer
;
648 * Get multiple files.
650 void mget(int argc
, const char *argv
[])
653 char *tp2
, tmpbuf
[MAXPATHLEN
];
655 extern jmp_buf jabort
;
658 (void) strcat(line
, " ");
659 printf("(remote-files) ");
660 (void) fflush(stdout
);
661 (void) gets(&line
[strlen(line
)]);
667 printf("usage:%s remote-files\n", argv
[0]);
668 (void) fflush(stdout
);
674 // oldintr = signal(SIGINT,mabort);
675 (void) setjmp(jabort
);
676 while ((cp
= remglob(argv
,proxy
)) != NULL
) {
681 if (mflag
&& confirm(argv
[0], cp
)) {
684 while (*tp
&& !islower(*tp
)) {
690 while ((*tp2
= *tp
)) {
692 *tp2
= 'a' + *tp2
- 'A';
706 recvrequest("RETR", tp
, cp
, "w",
707 tp
!= cp
|| !interactive
);
708 if (!mflag
&& fromatty
) {
709 ointer
= interactive
;
711 if (confirm("Continue with","mget")) {
714 interactive
= ointer
;
718 // (void) signal(SIGINT,oldintr);
723 remglob(const char *argv
[], int doswitch
)
726 static char buf
[MAXPATHLEN
];
727 static FILE *ftemp
= NULL
;
728 static const char **args
;
729 int oldverbose
, oldhash
;
740 (void) fclose(ftemp
);
749 if ((cp
= *++args
) == NULL
)
754 (void) strcpy(temp
, _PATH_TMP
);
756 oldverbose
= verbose
, verbose
= 0;
757 oldhash
= hash
, hash
= 0;
761 for (mode
= "w"; *++argv
!= NULL
; mode
= "a")
762 recvrequest ("NLST", temp
, *argv
, mode
, 0);
766 verbose
= oldverbose
; hash
= oldhash
;
767 ftemp
= fopen(temp
, "r");
770 printf("can't find list of remote files, oops\n");
771 (void) fflush(stdout
);
775 if (fgets(buf
, sizeof (buf
), ftemp
) == NULL
) {
776 (void) fclose(ftemp
), ftemp
= NULL
;
779 if ((terminator
= index(buf
, '\n')) != NULL
)
787 return (bool ? "on" : "off");
794 void status(int argc
, const char *argv
[])
799 printf("Connected to %s.\n", hostname
);
801 printf("Not connected.\n");
805 printf("Connected for proxy commands to %s.\n", hostname
);
808 printf("No proxy connection.\n");
812 printf("Mode: %s; Type: %s; Form: %s; Structure: %s\n",
813 modename
, typename
, formname
, structname
);
814 printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n",
815 onoff(verbose
), onoff(bell
), onoff(interactive
),
817 printf("Store unique: %s; Receive unique: %s\n", onoff(sunique
),
819 printf("Case: %s; CR stripping: %s\n",onoff(mcase
),onoff(crflag
));
821 printf("Ntrans: (in) %s (out) %s\n", ntin
,ntout
);
824 printf("Ntrans: off\n");
827 printf("Nmap: (in) %s (out) %s\n", mapin
, mapout
);
830 printf("Nmap: off\n");
832 printf("Hash mark printing: %s; Use of PORT cmds: %s\n",
833 onoff(hash
), onoff(sendport
));
836 for (i
=0; i
<macnum
; i
++) {
837 printf("\t%s\n",macros
[i
].mac_name
);
840 (void) fflush(stdout
);
845 * Set beep on cmd completed mode.
848 void setbell(int argc
, const char *argv
[])
852 printf("Bell mode %s.\n", onoff(bell
));
853 (void) fflush(stdout
);
858 * Turn on packet tracing.
861 void settrace(int argc
, const char *argv
[])
865 printf("Packet tracing %s.\n", onoff(trace
));
866 (void) fflush(stdout
);
871 * Toggle hash mark printing during transfers.
874 void sethash(int argc
, const char *argv
[])
878 printf("Hash mark printing %s", onoff(hash
));
881 printf(" (%d bytes/hash mark)", 1024);
883 (void) fflush(stdout
);
887 * Turn on printing of server echo's.
890 void setverbose(int argc
, const char *argv
[])
894 printf("Verbose mode %s.\n", onoff(verbose
));
895 (void) fflush(stdout
);
900 * Toggle PORT cmd use before each data connection.
903 void setport(int argc
, const char *argv
[])
906 sendport
= !sendport
;
907 printf("Use of PORT cmds %s.\n", onoff(sendport
));
908 (void) fflush(stdout
);
913 * Turn on interactive prompting
914 * during mget, mput, and mdelete.
917 void setprompt(int argc
, const char *argv
[])
920 interactive
= !interactive
;
921 printf("Interactive mode %s.\n", onoff(interactive
));
922 (void) fflush(stdout
);
927 * Toggle metacharacter interpretation
928 * on local file names.
931 void setglob(int argc
, const char *argv
[])
935 printf("Globbing %s.\n", onoff(doglob
));
936 (void) fflush(stdout
);
941 * Set debugging mode on/off and/or
942 * set level of debugging.
945 void setdebug(int argc
, const char *argv
[])
952 printf("%s: bad debugging value.\n", argv
[1]);
953 (void) fflush(stdout
);
963 options
&= ~SO_DEBUG
;
964 printf("Debugging %s (debug=%d).\n", onoff(debug
), debug
);
965 (void) fflush(stdout
);
970 * Set current working directory
973 void cd(int argc
, const char *argv
[])
977 (void) strcat(line
, " ");
978 printf("(remote-directory) ");
979 (void) fflush(stdout
);
980 (void) gets(&line
[strlen(line
)]);
986 printf("usage:%s remote-directory\n", argv
[0]);
987 (void) fflush(stdout
);
991 if (command("CWD %s", argv
[1]) == ERROR
&& code
== 500) {
993 printf("CWD command not recognized, trying XCWD\n");
994 (void) fflush(stdout
);
996 (void) command("XCWD %s", argv
[1]);
1001 * Set current working directory
1004 void lcd(int argc
, const char *argv
[])
1006 char buf
[MAXPATHLEN
];
1009 argc
++, argv
[1] = home
;
1011 printf("usage:%s local-directory\n", argv
[0]);
1012 (void) fflush(stdout
);
1016 if (!globulize(&argv
[1])) {
1020 if (chdir(argv
[1]) < 0) {
1025 printf("Local directory now %s\n", getcwd(buf
,sizeof(buf
)));
1026 (void) fflush(stdout
);
1031 * Delete a single file.
1033 void delete(int argc
, const char *argv
[])
1037 (void) strcat(line
, " ");
1038 printf("(remote-file) ");
1039 (void) fflush(stdout
);
1040 (void) gets(&line
[strlen(line
)]);
1046 printf("usage:%s remote-file\n", argv
[0]);
1047 (void) fflush(stdout
);
1051 (void) command("DELE %s", argv
[1]);
1055 * Delete multiple files.
1057 void mdelete(int argc
, const char *argv
[])
1061 extern jmp_buf jabort
;
1064 (void) strcat(line
, " ");
1065 printf("(remote-files) ");
1066 (void) fflush(stdout
);
1067 (void) gets(&line
[strlen(line
)]);
1073 printf("usage:%s remote-files\n", argv
[0]);
1074 (void) fflush(stdout
);
1080 // oldintr = signal(SIGINT, mabort);
1081 (void) setjmp(jabort
);
1082 while ((cp
= remglob(argv
,0)) != NULL
) {
1087 if (mflag
&& confirm(argv
[0], cp
)) {
1088 (void) command("DELE %s", cp
);
1089 if (!mflag
&& fromatty
) {
1090 ointer
= interactive
;
1092 if (confirm("Continue with", "mdelete")) {
1095 interactive
= ointer
;
1099 // (void) signal(SIGINT, oldintr);
1104 * Rename a remote file.
1106 void renamefile(int argc
, const char *argv
[])
1110 (void) strcat(line
, " ");
1111 printf("(from-name) ");
1112 (void) fflush(stdout
);
1113 (void) gets(&line
[strlen(line
)]);
1120 printf("%s from-name to-name\n", argv
[0]);
1121 (void) fflush(stdout
);
1126 (void) strcat(line
, " ");
1127 printf("(to-name) ");
1128 (void) fflush(stdout
);
1129 (void) gets(&line
[strlen(line
)]);
1136 if (command("RNFR %s", argv
[1]) == CONTINUE
)
1137 (void) command("RNTO %s", argv
[2]);
1141 * Get a directory listing
1144 void ls(int argc
, const char *argv
[])
1149 argc
++, argv
[1] = NULL
;
1151 argc
++, argv
[2] = "-";
1153 printf("usage: %s remote-directory local-file\n", argv
[0]);
1154 (void) fflush(stdout
);
1158 cmd
= argv
[0][0] == 'n' ? "NLST" : "LIST";
1159 // cmd = argv[0][0] == 'n' ? "NLST -CF" : "NLST -CF";
1160 if (strcmp(argv
[2], "-") && !globulize(&argv
[2])) {
1164 if (strcmp(argv
[2], "-") && *argv
[2] != '|')
1165 if (!globulize(&argv
[2]) || !confirm("output to local-file:", argv
[2])) {
1169 recvrequest(cmd
, argv
[2], argv
[1], "w", 0);
1173 * Get a directory listing
1174 * of multiple remote files.
1176 void mls(int argc
, const char *argv
[])
1178 const char *cmd
, *dest
;
1181 extern jmp_buf jabort
;
1184 (void) strcat(line
, " ");
1185 printf("(remote-files) ");
1186 (void) fflush(stdout
);
1187 (void) gets(&line
[strlen(line
)]);
1193 (void) strcat(line
, " ");
1194 printf("(local-file) ");
1195 (void) fflush(stdout
);
1196 (void) gets(&line
[strlen(line
)]);
1202 printf("usage:%s remote-files local-file\n", argv
[0]);
1203 (void) fflush(stdout
);
1207 dest
= argv
[argc
- 1];
1208 argv
[argc
- 1] = NULL
;
1209 if (strcmp(dest
, "-") && *dest
!= '|')
1210 if (!globulize(&dest
) || !confirm("output to local-file:", dest
)) {
1214 cmd
= argv
[0][1] == 'l' ? "NLST" : "LIST";
1217 // oldintr = signal(SIGINT, mabort);
1218 (void) setjmp(jabort
);
1219 for (i
= 1; mflag
&& i
< argc
-1; ++i
) {
1220 *mode
= (i
== 1) ? 'w' : 'a';
1221 recvrequest(cmd
, dest
, argv
[i
], mode
, 0);
1222 if (!mflag
&& fromatty
) {
1223 ointer
= interactive
;
1225 if (confirm("Continue with", argv
[0])) {
1228 interactive
= ointer
;
1231 // (void) signal(SIGINT, oldintr);
1239 void shell(int argc
, const char *argv
[])
1243 sig_t (*old1
)(), (*old2
)();
1244 char shellnam
[40], *shell
, *namep
;
1247 old1
= signal (SIGINT
, SIG_IGN
);
1248 old2
= signal (SIGQUIT
, SIG_IGN
);
1249 if ((pid
= fork()) == 0) {
1250 for (pid
= 3; pid
< 20; pid
++)
1252 (void) signal(SIGINT
, SIG_DFL
);
1253 (void) signal(SIGQUIT
, SIG_DFL
);
1254 shell
= getenv("SHELL");
1256 shell
= _PATH_BSHELL
;
1257 namep
= rindex(shell
,'/');
1260 (void) strcpy(shellnam
,"-");
1261 (void) strcat(shellnam
, ++namep
);
1262 if (strcmp(namep
, "sh") != 0)
1265 printf ("%s\n", shell
);
1266 (void) fflush (stdout
);
1269 execl(shell
,shellnam
,"-c",altarg
,(char *)0);
1272 execl(shell
,shellnam
,(char *)0);
1279 while (wait(&status
) != pid
)
1281 (void) signal(SIGINT
, old1
);
1282 (void) signal(SIGQUIT
, old2
);
1284 perror("Try again later");
1293 char ShellCmd
[MAX_PATH
];
1294 char CmdLine
[MAX_PATH
];
1296 PROCESS_INFORMATION ProcessInformation
;
1298 STARTUPINFO StartupInfo
;
1299 char ShellName
[] = "COMSPEC";
1302 NumBytes
= GetEnvironmentVariable( ShellName
, ShellCmd
, MAX_PATH
);
1310 strcpy( CmdLine
, ShellCmd
);
1314 strncat(CmdLine
, " /C", MAX_PATH
);
1317 for (i
=1; i
<argc
; i
++)
1319 strncat(CmdLine
, " ", MAX_PATH
);
1320 strncat(CmdLine
, argv
[i
], MAX_PATH
);
1323 StartupInfo
.cb
= sizeof( StartupInfo
);
1324 StartupInfo
.lpReserved
= NULL
;
1325 StartupInfo
.lpDesktop
= NULL
;
1326 StartupInfo
.lpTitle
= NULL
;
1327 StartupInfo
.dwX
= 0;
1328 StartupInfo
.dwY
= 0;
1329 StartupInfo
.dwXSize
= 0;
1330 StartupInfo
.dwYSize
= 0;
1331 StartupInfo
.dwFlags
= 0;
1332 StartupInfo
.wShowWindow
= 0;
1333 StartupInfo
.cbReserved2
= 0;
1334 StartupInfo
.lpReserved2
= NULL
;
1336 Result
= CreateProcess( AppName
, // cmd name
1337 CmdLine
, // cmd line arguments
1339 NULL
, // security attributes
1340 FALSE
, // inherit flags
1341 0, // Creation flags
1342 NULL
, // Environment
1343 NULL
, // Current directory
1344 &StartupInfo
, // Startup info structure
1345 &ProcessInformation
); // processInfo structure
1349 WaitForSingleObject( ProcessInformation
.hProcess
, 0xffffffff);
1351 CloseHandle( ProcessInformation
.hProcess
);
1356 * Send new user information (re-login)
1358 void user(int argc
, const char *argv
[])
1360 char acct
[80], *getpass();
1364 (void) strcat(line
, " ");
1365 printf("(username) ");
1366 (void) fflush(stdout
);
1367 (void) gets(&line
[strlen(line
)]);
1373 printf("usage: %s username [password] [account]\n", argv
[0]);
1374 (void) fflush(stdout
);
1378 n
= command("USER %s", argv
[1]);
1379 if (n
== CONTINUE
) {
1381 argv
[2] = getpass("Password: "), argc
++;
1382 n
= command("PASS %s", argv
[2]);
1384 if (n
== CONTINUE
) {
1386 printf("Account: "); (void) fflush(stdout
);
1387 (void) fflush(stdout
);
1388 (void) fgets(acct
, sizeof(acct
) - 1, stdin
);
1389 acct
[strlen(acct
) - 1] = '\0';
1390 argv
[3] = acct
; argc
++;
1392 n
= command("ACCT %s", argv
[3]);
1395 if (n
!= COMPLETE
) {
1396 fprintf(stdout
, "Login failed.\n");
1397 (void) fflush(stdout
);
1400 if (!aflag
&& argc
== 4) {
1401 (void) command("ACCT %s", argv
[3]);
1406 * Print working directory.
1409 void pwd(int argc
, const char *argv
[])
1411 int oldverbose
= verbose
;
1414 * If we aren't verbose, this doesn't do anything!
1417 if (command("PWD") == ERROR
&& code
== 500) {
1418 printf("PWD command not recognized, trying XPWD\n");
1419 (void) fflush(stdout
);
1420 (void) command("XPWD");
1422 verbose
= oldverbose
;
1428 void makedir(int argc
, const char *argv
[])
1432 (void) strcat(line
, " ");
1433 printf("(directory-name) ");
1434 (void) fflush(stdout
);
1435 (void) gets(&line
[strlen(line
)]);
1441 printf("usage: %s directory-name\n", argv
[0]);
1442 (void) fflush(stdout
);
1446 if (command("MKD %s", argv
[1]) == ERROR
&& code
== 500) {
1448 printf("MKD command not recognized, trying XMKD\n");
1449 (void) fflush(stdout
);
1451 (void) command("XMKD %s", argv
[1]);
1456 * Remove a directory.
1458 void removedir(int argc
, const char *argv
[])
1462 (void) strcat(line
, " ");
1463 printf("(directory-name) ");
1464 (void) fflush(stdout
);
1465 (void) gets(&line
[strlen(line
)]);
1471 printf("usage: %s directory-name\n", argv
[0]);
1472 (void) fflush(stdout
);
1476 if (command("RMD %s", argv
[1]) == ERROR
&& code
== 500) {
1478 printf("RMD command not recognized, trying XRMD\n");
1479 (void) fflush(stdout
);
1481 (void) command("XRMD %s", argv
[1]);
1486 * Send a line, verbatim, to the remote machine.
1488 void quote(int argc
, const char *argv
[])
1494 (void) strcat(line
, " ");
1495 printf("(command line to send) ");
1496 (void) fflush(stdout
);
1497 (void) gets(&line
[strlen(line
)]);
1503 printf("usage: %s line-to-send\n", argv
[0]);
1504 (void) fflush(stdout
);
1508 (void) strcpy(buf
, argv
[1]);
1509 for (i
= 2; i
< argc
; i
++) {
1510 (void) strcat(buf
, " ");
1511 (void) strcat(buf
, argv
[i
]);
1513 if (command(buf
) == PRELIM
) {
1514 while (getreply(0) == PRELIM
);
1519 * Send a SITE command to the remote machine. The line
1520 * is sent almost verbatim to the remote machine, the
1521 * first argument is changed to SITE.
1523 void site(int argc
, const char *argv
[])
1529 (void) strcat(line
, " ");
1530 printf("(arguments to SITE command) ");
1531 (void) fflush(stdout
);
1532 (void) gets(&line
[strlen(line
)]);
1538 printf("usage: %s line-to-send\n", argv
[0]);
1539 (void) fflush(stdout
);
1543 (void) strcpy(buf
, "SITE ");
1544 (void) strcat(buf
, argv
[1]);
1545 for (i
= 2; i
< argc
; i
++) {
1546 (void) strcat(buf
, " ");
1547 (void) strcat(buf
, argv
[i
]);
1549 if (command(buf
) == PRELIM
) {
1550 while (getreply(0) == PRELIM
);
1554 void do_chmod(int argc
, const char *argv
[])
1557 printf("usage: %s mode file-name\n", argv
[0]);
1558 (void) fflush(stdout
);
1563 (void) strcat(line
, " ");
1564 printf("(mode and file-name) ");
1565 (void) fflush(stdout
);
1566 (void) gets(&line
[strlen(line
)]);
1572 printf("usage: %s mode file-name\n", argv
[0]);
1573 (void) fflush(stdout
);
1577 (void)command("SITE CHMOD %s %s", argv
[1], argv
[2]);
1580 void do_umask(int argc
, const char *argv
[])
1582 int oldverbose
= verbose
;
1585 (void) command(argc
== 1 ? "SITE UMASK" : "SITE UMASK %s", argv
[1]);
1586 verbose
= oldverbose
;
1589 void idle(int argc
, const char *argv
[])
1591 int oldverbose
= verbose
;
1594 (void) command(argc
== 1 ? "SITE IDLE" : "SITE IDLE %s", argv
[1]);
1595 verbose
= oldverbose
;
1599 * Ask the other side for help.
1601 void rmthelp(int argc
, const char *argv
[])
1603 int oldverbose
= verbose
;
1606 (void) command(argc
== 1 ? "HELP" : "HELP %s", argv
[1]);
1607 verbose
= oldverbose
;
1611 * Terminate session and exit.
1614 void quit(int argc
, const char *argv
[])
1617 disconnect(0, NULL
);
1620 disconnect(0, NULL
);
1626 * Terminate session, but don't exit.
1628 void disconnect(int argc
, const char *argv
[])
1635 (void) command("QUIT");
1644 int confirm(const char *cmd
, const char *file
)
1650 printf("%s %s? ", cmd
, file
);
1651 (void) fflush(stdout
);
1653 return (*line
!= 'n' && *line
!= 'N');
1657 static void fatal(const char *msg
)
1660 fprintf(stderr
, "ftp: %s\n", msg
);
1666 * Glob a local file name specification with
1667 * the expectation of a single return value.
1668 * Can't control multiple values being expanded
1669 * from the expression, we return only the first.
1671 int globulize(const char **cpp
)
1677 globbed
= glob(*cpp
);
1678 if (globerr
!= NULL
) {
1679 printf("%s: %s\n", *cpp
, globerr
);
1680 (void) fflush(stdout
);
1683 free((char *)globbed
);
1689 /* don't waste too much memory */
1692 free((char *)globbed
);
1698 void account(int argc
, const char *argv
[])
1700 char acct
[50], *getpass(), *ap
;
1705 (void) strncpy(acct
,*argv
,49);
1710 (void) strncat(acct
,*argv
, 49-strlen(acct
));
1715 ap
= getpass("Account:");
1717 (void) command("ACCT %s", ap
);
1738 longjmp(abortprox
,1);
1742 void doproxy(int argc
, const char *argv
[])
1744 register struct cmd
*c
;
1745 struct cmd
*getcmd();
1746 // extern struct cmd cmdtab[];
1747 extern jmp_buf abortprox
;
1750 (void) strcat(line
, " ");
1751 printf("(command) ");
1752 (void) fflush(stdout
);
1753 (void) gets(&line
[strlen(line
)]);
1759 printf("usage:%s command\n", argv
[0]);
1760 (void) fflush(stdout
);
1764 c
= getcmd(argv
[1]);
1765 if (c
== (struct cmd
*) -1) {
1766 printf("?Ambiguous command\n");
1767 (void) fflush(stdout
);
1772 printf("?Invalid command\n");
1773 (void) fflush(stdout
);
1778 printf("?Invalid proxy command\n");
1779 (void) fflush(stdout
);
1783 if (setjmp(abortprox
)) {
1787 // oldintr = signal(SIGINT, proxabort);
1789 if (c
->c_conn
&& !connected
) {
1790 printf("Not connected\n");
1791 (void) fflush(stdout
);
1793 // (void) signal(SIGINT, oldintr);
1797 (*c
->c_handler
)(argc
-1, argv
+1);
1805 // (void) signal(SIGINT, oldintr);
1808 void setcase(int argc
, const char *argv
[])
1811 printf("Case mapping %s.\n", onoff(mcase
));
1812 (void) fflush(stdout
);
1816 void setcr(int argc
, const char *argv
[])
1819 printf("Carriage Return stripping %s.\n", onoff(crflag
));
1820 (void) fflush(stdout
);
1824 void setntrans(int argc
, const char *argv
[])
1828 printf("Ntrans off.\n");
1829 (void) fflush(stdout
);
1835 (void) strncpy(ntin
, argv
[1], 16);
1841 (void) strncpy(ntout
, argv
[2], 16);
1846 dotrans(const char *name
)
1848 static char new[MAXPATHLEN
];
1851 register int i
, ostop
, found
;
1853 for (ostop
= 0; *(ntout
+ ostop
) && ostop
< 16; ostop
++);
1854 for (cp1
= name
; *cp1
; cp1
++) {
1856 for (i
= 0; *(ntin
+ i
) && i
< 16; i
++) {
1857 if (*cp1
== *(ntin
+ i
)) {
1860 *cp2
++ = *(ntout
+ i
);
1873 void setpassive(int argc
, const char *argv
[])
1875 passivemode
= !passivemode
;
1876 printf("Passive mode %s.\n", onoff(passivemode
));
1877 (void) fflush(stdout
);
1881 void setnmap(int argc
, const char *argv
[])
1887 printf("Nmap off.\n");
1888 (void) fflush(stdout
);
1893 (void) strcat(line
, " ");
1894 printf("(mapout) ");
1895 (void) fflush(stdout
);
1896 (void) gets(&line
[strlen(line
)]);
1902 printf("Usage: %s [mapin mapout]\n",argv
[0]);
1903 (void) fflush(stdout
);
1909 cp
= index(altarg
, ' ');
1911 while(*++cp
== ' ');
1913 cp
= index(altarg
, ' ');
1916 (void) strncpy(mapin
, altarg
, MAXPATHLEN
- 1);
1917 while (*++cp
== ' ');
1918 (void) strncpy(mapout
, cp
, MAXPATHLEN
- 1);
1922 domap(const char *name
)
1924 static char new[MAXPATHLEN
];
1925 const char *cp1
= name
;
1926 char *cpn
, *cp2
= mapin
;
1927 const char *tp
[9], *te
[9];
1928 int i
, toks
[9], toknum
= 0, match
= 1;
1930 for (i
=0; i
< 9; ++i
) {
1933 while (match
&& *cp1
&& *cp2
) {
1936 if (*++cp2
!= *cp1
) {
1941 if (*(cp2
+1) >= '1' && (*cp2
+1) <= '9') {
1942 if (*cp1
!= *(++cp2
+1)) {
1943 toks
[toknum
= *cp2
- '1']++;
1945 while (*++cp1
&& *(cp2
+1)
1959 if (match
&& *cp1
) {
1962 if (match
&& *cp2
) {
1966 if (!match
&& *cp1
) /* last token mismatch */
1984 if (*++cp2
== '$' && isdigit(*(cp2
+1))) {
1985 if (*++cp2
== '0') {
1986 const char *cp3
= name
;
1993 else if (toks
[toknum
= *cp2
- '1']) {
1994 const char *cp3
= tp
[toknum
];
1996 while (cp3
!= te
[toknum
]) {
2003 while (*cp2
&& *cp2
!= ',' &&
2008 else if (*cp2
== '$' &&
2009 isdigit(*(cp2
+1))) {
2010 if (*++cp2
== '0') {
2011 const char *cp3
= name
;
2017 else if (toks
[toknum
=
2019 const char *cp3
=tp
[toknum
];
2032 printf("nmap: unbalanced brackets\n");
2033 (void) fflush(stdout
);
2040 while (*++cp2
&& *cp2
!= ']') {
2041 if (*cp2
== '\\' && *(cp2
+ 1)) {
2046 printf("nmap: unbalanced brackets\n");
2047 (void) fflush(stdout
);
2063 if (isdigit(*(cp2
+ 1))) {
2064 if (*++cp2
== '0') {
2065 const char *cp3
= name
;
2071 else if (toks
[toknum
= *cp2
- '1']) {
2072 const char *cp3
= tp
[toknum
];
2074 while (cp3
!= te
[toknum
]) {
2080 /* intentional drop through */
2094 void setsunique(int argc
, const char *argv
[])
2097 printf("Store unique %s.\n", onoff(sunique
));
2098 (void) fflush(stdout
);
2102 void setrunique(int argc
, const char *argv
[])
2105 printf("Receive unique %s.\n", onoff(runique
));
2106 (void) fflush(stdout
);
2110 /* change directory to perent directory */
2111 void cdup(int argc
, const char *argv
[])
2113 if (command("CDUP") == ERROR
&& code
== 500) {
2115 printf("CDUP command not recognized, trying XCUP\n");
2116 (void) fflush(stdout
);
2118 (void) command("XCUP");
2122 /* restart transfer at specific point */
2123 void restart(int argc
, const char *argv
[])
2126 printf("restart: offset not specified\n");
2128 restart_point
= atol(argv
[1]);
2129 printf("restarting at %ld. %s\n", restart_point
,
2130 "execute get, put or append to initiate transfer");
2132 (void) fflush(stdout
);
2135 /* show remote system type */
2136 void syst(int argc
, const char *argv
[])
2138 (void) command("SYST");
2141 void macdef(int argc
, const char *argv
[])
2147 printf("Limit of 16 macros have already been defined\n");
2148 (void) fflush(stdout
);
2153 (void) strcat(line
, " ");
2154 printf("(macro name) ");
2155 (void) fflush(stdout
);
2156 (void) gets(&line
[strlen(line
)]);
2162 printf("Usage: %s macro_name\n",argv
[0]);
2163 (void) fflush(stdout
);
2168 printf("Enter macro line by line, terminating it with a null line\n");
2169 (void) fflush(stdout
);
2171 (void) strncpy(macros
[macnum
].mac_name
, argv
[1], 8);
2173 macros
[macnum
].mac_start
= macbuf
;
2176 macros
[macnum
].mac_start
= macros
[macnum
- 1].mac_end
+ 1;
2178 tmp
= macros
[macnum
].mac_start
;
2179 while (tmp
!= macbuf
+4096) {
2180 if ((c
= getchar()) == EOF
) {
2181 printf("macdef:end of file encountered\n");
2182 (void) fflush(stdout
);
2186 if ((*tmp
= c
) == '\n') {
2187 if (tmp
== macros
[macnum
].mac_start
) {
2188 macros
[macnum
++].mac_end
= tmp
;
2192 if (*(tmp
-1) == '\0') {
2193 macros
[macnum
++].mac_end
= tmp
- 1;
2202 while ((c
= getchar()) != '\n' && c
!= EOF
)
2204 if (c
== EOF
|| getchar() == '\n') {
2205 printf("Macro not defined - 4k buffer exceeded\n");
2206 (void) fflush(stdout
);
2214 * get size of file on remote machine
2216 void sizecmd(int argc
, const char *argv
[])
2220 (void) strcat(line
, " ");
2221 printf("(filename) ");
2222 (void) fflush(stdout
);
2223 (void) gets(&line
[strlen(line
)]);
2229 printf("usage:%s filename\n", argv
[0]);
2230 (void) fflush(stdout
);
2234 (void) command("SIZE %s", argv
[1]);
2238 * get last modification time of file on remote machine
2240 void modtime(int argc
, const char *argv
[])
2245 (void) strcat(line
, " ");
2246 printf("(filename) ");
2247 (void) fflush(stdout
);
2248 (void) gets(&line
[strlen(line
)]);
2254 printf("usage:%s filename\n", argv
[0]);
2255 (void) fflush(stdout
);
2262 if (command("MDTM %s", argv
[1]) == COMPLETE
) {
2263 int yy
, mo
, day
, hour
, min
, sec
;
2264 sscanf(reply_string
, "%*s %04d%02d%02d%02d%02d%02d", &yy
, &mo
,
2265 &day
, &hour
, &min
, &sec
);
2266 /* might want to print this in local time */
2267 printf("%s\t%02d/%02d/%04d %02d:%02d:%02d GMT\n", argv
[1],
2268 mo
, day
, yy
, hour
, min
, sec
);
2270 printf("%s\n", reply_string
);
2272 (void) fflush(stdout
);
2276 * show status on reomte machine
2278 void rmtstatus(int argc
, const char *argv
[])
2280 (void) command(argc
> 1 ? "STAT %s" : "STAT" , argv
[1]);
2284 * get file if modtime is more recent than current file
2286 void newer(int argc
, const char *argv
[])
2288 if (getit(argc
, argv
, -1, "w")) {
2289 printf("Local file \"%s\" is newer than remote file \"%s\"\n",
2291 (void) fflush(stdout
);