Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/RB-1.1/ftpdel.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 13 - (show annotations) (download) (as text)
Mon Feb 23 02:22:49 2009 UTC (15 years ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 3112 byte(s)
Creating relase branch for 1.1
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_del:
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 ***/
50
51 int ftp_del (int sck, char *FileName, int verbose)
52 {
53 char buffer[1024]={'\0'};
54 char *buf;
55 int n = 0;
56 struct timeval tm; //tv_sec - tv_usec
57 fd_set readfds;
58
59
60 buf=(char *)malloc(1024*sizeof(char));
61
62 memset(buffer, 0x0, 1024);
63 memset(buf, 0x0, 1024);
64
65 if ( strlen(FileName) > 1015 ) {
66 free(buffer);
67 free(buf);
68
69 return DIR_TOO_LONG;
70 }
71
72 sprintf(buffer, "DELE %s\r\n", FileName);
73
74 if (write(sck, buffer, strlen(buffer)) == -1) {
75
76
77 if (verbose) {
78 if (errno == EBADF) {
79 fprintf(stderr, "Socket Descriptor Not Valid!\n");
80 free(buf);
81
82 return -1;
83 } else if (errno == EIO) {
84 fprintf(stderr, "I/O Error!\n");
85 free(buf);
86
87 return -1;
88 } else if (errno == EINTR) {
89 fprintf(stderr, "Signal Interrupted The write() Function\n");
90 free(buf);
91
92 return -1;
93 }
94
95 } else {
96
97 if (errno == EBADF) {
98 free(buf);
99
100 return -1;
101 } else if (errno == EIO) {
102 free(buf);
103
104 return -1;
105 } else if (errno == EINTR) {
106 free(buf);
107
108 return -1;
109 }
110
111 }
112
113 free(buf);
114
115 return -1;
116
117 }
118
119 tm.tv_sec = 3;
120 tm.tv_usec = 0;
121
122 FD_ZERO(&readfds);
123
124 FD_SET(sck, &readfds);
125
126 if (select(sck+1, &readfds, NULL, NULL, &tm) < 0 ) {
127 if (verbose) {
128 perror("select()");
129 }
130 free(buf);
131
132 return -1;
133 } else {
134
135
136 if (FD_ISSET(sck, &readfds)) {
137
138 if ( (n = recv(sck, buf, 1022, 0)) < 0) {
139 if (verbose) {
140 perror("recv()");
141 }
142 free(buf);
143
144 return -1;
145 }
146
147 if (verbose)
148 printf("[Server] %s\n", buf);
149
150 }
151 else {
152 if (verbose)
153 printf("[-] Timeout\n");
154
155 return -1;
156 }
157 }
158
159 buf[n] = '\0';
160
161 if (ftp_file_handler(buf, 0) != 0) {
162 free(buf);
163
164 return -1;
165 }
166
167 free(buf);
168
169 return 0; //Removed!
170
171 }

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