1 | /* local.c
|
---|
2 | *
|
---|
3 | * This file is part of ftp.
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * 01/25/96 Initial Release Michael Temari, <temari@ix.netcom.com>
|
---|
7 | */
|
---|
8 |
|
---|
9 | #include <sys/types.h>
|
---|
10 | #include <sys/stat.h>
|
---|
11 | #include <stdio.h>
|
---|
12 | #include <unistd.h>
|
---|
13 | #include <string.h>
|
---|
14 | #include <stdlib.h>
|
---|
15 | #include <errno.h>
|
---|
16 |
|
---|
17 | #include "ftp.h"
|
---|
18 | #include "local.h"
|
---|
19 |
|
---|
20 | static char line2[512];
|
---|
21 |
|
---|
22 | _PROTOTYPE(static void dodir, (char *path, int full));
|
---|
23 |
|
---|
24 | int DOlpwd()
|
---|
25 | {
|
---|
26 | if(getcwd(line2, sizeof(line2)) == (char *)NULL)
|
---|
27 | printf("Could not determine local directory. %s\n", strerror(errno));
|
---|
28 | else
|
---|
29 | printf("Current local directory: %s\n", line2);
|
---|
30 |
|
---|
31 | return(0);
|
---|
32 | }
|
---|
33 |
|
---|
34 | int DOlcd()
|
---|
35 | {
|
---|
36 | char *path;
|
---|
37 | int s;
|
---|
38 |
|
---|
39 | path = cmdargv[1];
|
---|
40 |
|
---|
41 | if(cmdargc < 2) {
|
---|
42 | readline("Path: ", line2, sizeof(line2));
|
---|
43 | path = line2;
|
---|
44 | }
|
---|
45 |
|
---|
46 | if(chdir(path))
|
---|
47 | printf("Could not change local directory. %s\n", strerror(errno));
|
---|
48 | else
|
---|
49 | DOlpwd();
|
---|
50 |
|
---|
51 | return(0);
|
---|
52 | }
|
---|
53 |
|
---|
54 | int DOlmkdir()
|
---|
55 | {
|
---|
56 | char *path;
|
---|
57 | int s;
|
---|
58 |
|
---|
59 | path = cmdargv[1];
|
---|
60 |
|
---|
61 | if(cmdargc < 2) {
|
---|
62 | readline("Directory: ", line2, sizeof(line2));
|
---|
63 | path = line2;
|
---|
64 | }
|
---|
65 |
|
---|
66 | if(mkdir(path, 0777))
|
---|
67 | printf("Could not make directory %s. %s\n", path, strerror(errno));
|
---|
68 | else
|
---|
69 | printf("Directory created.\n");
|
---|
70 |
|
---|
71 | return(0);
|
---|
72 | }
|
---|
73 |
|
---|
74 | int DOlrmdir()
|
---|
75 | {
|
---|
76 | char *path;
|
---|
77 | int s;
|
---|
78 |
|
---|
79 | path = cmdargv[1];
|
---|
80 |
|
---|
81 | if(cmdargc < 2) {
|
---|
82 | readline("Directory: ", line2, sizeof(line2));
|
---|
83 | path = line2;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if(rmdir(path))
|
---|
87 | printf("Could not remove directory %s. %s\n", path, strerror(errno));
|
---|
88 | else
|
---|
89 | printf("Directory removed.\n");
|
---|
90 |
|
---|
91 | return(0);
|
---|
92 | }
|
---|
93 |
|
---|
94 | int DOllist(void)
|
---|
95 | {
|
---|
96 | dodir(".", 1);
|
---|
97 | }
|
---|
98 |
|
---|
99 | int DOlnlst(void)
|
---|
100 | {
|
---|
101 | dodir(".", 0);
|
---|
102 | }
|
---|
103 |
|
---|
104 | int DOlshell(void)
|
---|
105 | {
|
---|
106 | system("$SHELL");
|
---|
107 | }
|
---|
108 |
|
---|
109 | static void dodir(path, full)
|
---|
110 | char *path;
|
---|
111 | int full;
|
---|
112 | {
|
---|
113 | char cmd[128];
|
---|
114 | static char name[32];
|
---|
115 |
|
---|
116 | tmpnam(name);
|
---|
117 |
|
---|
118 | if(full)
|
---|
119 | sprintf(cmd, "ls -l %s > %s", path, name);
|
---|
120 | else
|
---|
121 | sprintf(cmd, "ls %s > %s", path, name);
|
---|
122 |
|
---|
123 | system(cmd);
|
---|
124 | sprintf(cmd, "more %s", name);
|
---|
125 | system(cmd);
|
---|
126 | sprintf(cmd, "rm %s", name);
|
---|
127 | system(cmd);
|
---|
128 | }
|
---|