Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /tags/REL-1.1/ftprmd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations) (download) (as text)
Wed Feb 18 08:06:53 2009 UTC (15 years, 1 month ago) by hirohitohigashi
Original Path: trunk/ftprmd.c
File MIME type: text/x-csrc
File size: 3041 byte(s)
Initial import. original is libOftp_1_0.tar.gz.
1 hirohitohigashi 1 /*
2    
3     libftp 1.0 (stable): this is an FTP library to simplify the work to a Developer
4     who want to work with FTP servers (RFC 959).
5     Copyright (C) 2007/2008 omnipresent - omnipresent[at]email.it
6    
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program. If not, see <http://www.gnu.org/licenses/>.
19    
20     */
21    
22     #include <stdio.h>
23     #include <string.h>
24     #include <errno.h>
25     #include <stdlib.h>
26     #include <unistd.h>
27     #include <sys/types.h>
28     #include <sys/time.h>
29     #include <sys/socket.h>
30     #include <sys/stat.h>
31     #include <netinet/in.h>
32     #include <netdb.h>
33     #include <fcntl.h>
34    
35     #include "ftp_main.h"
36    
37     #define DIR_TOO_LONG 2
38     #define NAME_TOO_LONG 2
39    
40     /***
41     ftp_rmd:
42     - int sck => Socket Descriptor
43     - int verbose => Verbose?
44     . 0 Do not Print
45     . 1 Print
46     - ret => Success?
47     . 0 Success
48     .-1 Error
49     . 2 Error
50     ***/
51    
52    
53     int ftp_rmd (int sck, char *Directory, int verbose) {
54    
55     char buffer[1024]={'\0'};
56     char *buf;
57     int n = 0;
58    
59     buf = (char *)malloc(1024*sizeof(char));
60    
61     memset(buffer, 0x0, 1024);
62     memset(buf, 0x0, 1024);
63    
64    
65     if ( strlen(Directory) > 1015 ) {
66     free(buf);
67    
68     return DIR_TOO_LONG;
69     }
70    
71     sprintf(buffer, "RMD %s\n", Directory);
72    
73    
74    
75     if (write(sck, buffer, strlen(buffer)) == -1) {
76    
77    
78     if (verbose) {
79     if (errno == EBADF) {
80     fprintf(stderr, "Socket Descriptor Not Valid!\n");
81     free(buf);
82    
83     return -1;
84     } else if (errno == EIO) {
85     fprintf(stderr, "I/O Error!\n");
86     free(buf);
87    
88     return -1;
89     } else if (errno == EINTR) {
90     fprintf(stderr, "Signal Interrupted The write() Function\n");
91     free(buf);
92    
93     return -1;
94     }
95    
96     } else {
97    
98     if (errno == EBADF) {
99     free(buf);
100    
101     return -1;
102     } else if (errno == EIO) {
103     free(buf);
104    
105     return -1;
106     } else if (errno == EINTR) {
107     free(buf);
108    
109     return -1;
110     }
111    
112     }
113    
114     free(buf);
115    
116     return -1;
117    
118     }
119    
120    
121     sleep(1); //wait..
122     struct timeval tm; //tv_sec - tv_usec
123     fd_set readfds;
124     tm.tv_sec = 3;
125     tm.tv_usec = 0;
126    
127     FD_ZERO(&readfds);
128    
129     FD_SET(sck, &readfds);
130    
131     if (select(sck+1, &readfds, NULL, NULL, &tm) < 0 ) {
132     if (verbose) {
133     perror("select()");
134     }
135     free(buf);
136    
137     return -1;
138     } else {
139    
140     if (FD_ISSET(sck, &readfds)) {
141    
142     if ( (n = recv(sck, buf, 1022, 0)) < 0) {
143     if (verbose) {
144     perror("recv()");
145     }
146     free(buf);
147    
148     return -1;
149     }
150    
151     if (verbose)
152     printf("[Server] %s\n", buf);
153    
154     }
155     else {
156     if (verbose)
157     printf("[-] Timeout\n");
158    
159     return -1;
160     }
161     }
162    
163     buf[n] = '\0';
164    
165     if (ftp_dir_handler(buf, 0) != 0) {
166     free(buf);
167    
168     return -1; //Error
169     }
170    
171     free(buf);
172    
173     return 0; //Removed!
174    
175     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26