Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/ftpmkd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (hide annotations) (download) (as text)
Fri Feb 20 12:10:40 2009 UTC (15 years, 1 month ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 2916 byte(s)
moved variable declaration  for traditional compilers. such as QNX6.2.

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    
38     #define DIR_TOO_LONG 2
39     #define NAME_TOO_LONG 2
40    
41     /***
42     ftp_mkd:
43     - int sck => Socket Descriptor
44     - int verbose => Verbose?
45     . 0 Do not Print
46     . 1 Print
47     - ret => Success?
48     . 0 Success
49     .-1 Error
50     . 2 Error
51     ***/
52    
53    
54    
55 hirohitohigashi 7 int ftp_mkd (int sck, char *Directory, int verbose)
56     {
57     char buffer[1024];
58     char buf[1024];
59     int n;
60     struct timeval tm; //tv_sec - tv_usec
61     fd_set readfds;
62 hirohitohigashi 1
63 hirohitohigashi 7
64     memset(buf, 0x0, 1024);
65     memset(buffer, 0x0, 1024);
66 hirohitohigashi 1
67 hirohitohigashi 7 if ( strlen(Directory) > 1015 ) {
68 hirohitohigashi 1
69     return DIR_TOO_LONG;
70 hirohitohigashi 7 }
71 hirohitohigashi 1
72    
73 hirohitohigashi 7 sprintf(buffer, "MKD %s\n", Directory);
74 hirohitohigashi 1
75    
76 hirohitohigashi 7 if (write(sck, buffer, strlen(buffer)) == -1) {
77 hirohitohigashi 1
78     if (verbose) {
79 hirohitohigashi 7 if (errno == EBADF) {
80 hirohitohigashi 1 fprintf(stderr, "Socket Descriptor Not Valid!\n");
81    
82     return -1;
83 hirohitohigashi 7 } else if (errno == EIO) {
84 hirohitohigashi 1 fprintf(stderr, "I/O Error!\n");
85    
86     return -1;
87 hirohitohigashi 7 } else if (errno == EINTR) {
88 hirohitohigashi 1 fprintf(stderr, "Signal Interrupted The write() Function\n");
89    
90     return -1;
91 hirohitohigashi 7 }
92 hirohitohigashi 1
93     } else {
94    
95 hirohitohigashi 7 if (errno == EBADF) {
96 hirohitohigashi 1
97     return -1;
98 hirohitohigashi 7 } else if (errno == EIO) {
99 hirohitohigashi 1
100     return -1;
101 hirohitohigashi 7 } else if (errno == EINTR) {
102 hirohitohigashi 1
103     return -1;
104 hirohitohigashi 7 }
105 hirohitohigashi 1
106     }
107    
108    
109 hirohitohigashi 7 return -1;
110 hirohitohigashi 1
111 hirohitohigashi 7 }
112 hirohitohigashi 1
113    
114 hirohitohigashi 7 sleep(1); //wait..
115     tm.tv_sec = 3;
116     tm.tv_usec = 0;
117 hirohitohigashi 1
118 hirohitohigashi 7 FD_ZERO(&readfds);
119 hirohitohigashi 1
120 hirohitohigashi 7 FD_SET(sck, &readfds);
121 hirohitohigashi 1
122 hirohitohigashi 7 if (select(sck+1, &readfds, NULL, NULL, &tm) < 0 ) {
123     if (verbose) {
124     perror("select()");
125     }
126     return -1;
127     } else {
128    
129     if (FD_ISSET(sck, &readfds)) {
130    
131     if ( (n = recv(sck, buf, 1022, 0)) < 0) {
132 hirohitohigashi 1 if (verbose) {
133 hirohitohigashi 7 perror("recv()");
134 hirohitohigashi 1 }
135     return -1;
136 hirohitohigashi 7 }
137 hirohitohigashi 1
138 hirohitohigashi 7 if (verbose) {
139     printf("[Server] %s\n", buf);
140     }
141     }
142     else {
143     if (verbose)
144     printf("[-] Timeout\n");
145 hirohitohigashi 1
146 hirohitohigashi 7 return -1;
147 hirohitohigashi 1 }
148 hirohitohigashi 7 }
149 hirohitohigashi 1
150 hirohitohigashi 7 buf[n] = '\0';
151 hirohitohigashi 1
152 hirohitohigashi 7 if (ftp_dir_handler(buf, 0) != 0) {
153 hirohitohigashi 1
154 hirohitohigashi 7 return -1;
155     }
156 hirohitohigashi 1
157    
158 hirohitohigashi 7 return 0;
159 hirohitohigashi 1 }

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