23 #include <netinet/in.h> 35 buf[
sizeof (buf) - 1] =
'\0';
36 n =
recv_line (soc, buf,
sizeof (buf) - 1);
40 if (strncmp (buf,
"220", 3) != 0)
46 while (buf[3] ==
'-' && n > 0 &&
counter < 1024)
48 n =
recv_line (soc, buf,
sizeof (buf) - 1);
58 snprintf (buf,
sizeof (buf),
"USER %s\r\n", username);
60 n =
recv_line (soc, buf,
sizeof (buf) - 1);
63 if (strncmp (buf,
"230", 3) == 0)
66 while (buf[3] ==
'-' && n > 0 &&
counter < 1024)
68 n =
recv_line (soc, buf,
sizeof (buf) - 1);
74 if (strncmp (buf,
"331", 3) != 0)
81 while (buf[3] ==
'-' && n > 0 &&
counter < 1024)
83 n =
recv_line (soc, buf,
sizeof (buf) - 1);
90 snprintf (buf,
sizeof (buf),
"PASS %s\r\n", passwd);
92 n =
recv_line (soc, buf,
sizeof (buf) - 1);
96 if (strncmp (buf,
"230", 3) != 0)
103 while (buf[3] ==
'-' && n > 0 &&
counter < 1024)
105 n =
recv_line (soc, buf,
sizeof (buf) - 1);
121 snprintf (buf, 7,
"PASV\r\n");
123 bzero (buf,
sizeof (buf));
124 bzero (addr,
sizeof (
struct sockaddr_in));
125 if (
recv_line (soc, buf,
sizeof (buf) - 1) < 0)
128 if (strncmp (buf,
"227", 3) != 0)
131 t = strchr (buf,
'(');
141 l[0] = (
unsigned char) atoi (t);
147 l[1] = (
unsigned char) atoi (s);
153 l[2] = (
unsigned char) atoi (t);
159 l[3] = (
unsigned char) atoi (s);
165 l[4] = (
unsigned char) atoi (t);
171 l[5] = (
unsigned char) atoi (s);
172 a = (
unsigned long *) l;
173 p = (
unsigned short *) (l + 4);
175 addr->sin_addr.s_addr = *a;
177 addr->sin_family = AF_INET;
int recv_line(int soc, char *buf, size_t bufsiz)
Reads a text from the socket stream into the argument buffer, always.
Header file for module network.
int write_stream_connection(int fd, void *buf0, int n)
int ftp_log_in(int soc, char *username, char *passwd)
int ftp_get_pasv_address(int soc, struct sockaddr_in *addr)