1 // gcc -Wall -g rocksock.c rocksock_test2.c -o rocksock_test2
7 * License: LGPL 2.1+ with static linking exception
15 #include "../rocksock.h"
16 //RcB: DEP "../rocksock.c"
18 #define checkerr if(ret) { \
19 if(sock.lasterror.failedProxy != -1) printf("failing proxy: %d\n", sock.lasterror.failedProxy); \
20 printf("%s:%d - error #%d: %s from %s:%d\n", __FILE__, __LINE__, sock.lasterror.error, sock.lasterror.errormsg, sock.lasterror.file, sock.lasterror.line); \
24 int main(int argc
, char** argv
) {
26 rocksock
* psock
= &sock
;
30 size_t chunksize
= 512;
33 puts("need ip or dns name of a ftpserver as argv1");
41 rocksock_set_timeout(psock
, 10000);
42 //ret = rocksock_connect(psock, "b12.wimbli.com", 80, 0);
43 rocksock_add_proxy(psock
, RS_PT_SOCKS4
, "127.0.0.1", 9050, NULL
, NULL
);
44 //rocksock_add_proxy(psock, RS_PT_SOCKS5, "127.0.0.1", 31337, NULL, NULL);
45 //rocksock_add_proxy(psock, RS_PT_SOCKS5, "98.216.80.12", 5639, NULL, NULL);
48 ret
= rocksock_connect(psock
, argv
[1],
57 ret
= rocksock_readline(psock
, inbuf
, sizeof(inbuf
)-1, &bytesread
);
59 if(bytesread
) puts(inbuf
);
60 } while (bytesread
&& memcmp(inbuf
, "220 ", 4));
62 ret
= rocksock_send(psock
, inbuf
, snprintf(inbuf
, sizeof(inbuf
), "USER ftp\r\n"), 0, &bytesread
);
67 ret
= rocksock_readline(psock
, inbuf
, sizeof(inbuf
)-1, &bytesread
);
69 if(bytesread
) puts(inbuf
);
70 } while (bytesread
&& memcmp(inbuf
, "331 ", 4));
72 ret
= rocksock_send(psock
, inbuf
, snprintf(inbuf
, sizeof(inbuf
), "PASS none\r\n"), 0, &bytesread
);
77 ret
= rocksock_readline(psock
, inbuf
, sizeof(inbuf
)-1, &bytesread
);
79 if(bytesread
) puts(inbuf
);
80 } while (bytesread
&& memcmp(inbuf
, "230 ", 4));
82 ret
= rocksock_send(psock
, inbuf
, snprintf(inbuf
, sizeof(inbuf
), "PASV\r\n"), 0, &bytesread
);
87 ret
= rocksock_readline(psock
, inbuf
, sizeof(inbuf
)-1, &bytesread
);
89 if(bytesread
) puts(inbuf
);
90 } while (bytesread
&& memcmp(inbuf
, "230 ", 4));
92 ret
= rocksock_send(psock
, inbuf
, snprintf(inbuf
, sizeof(inbuf
), "LIST\r\n"), 0, &bytesread
);
97 ret
= rocksock_readline(psock
, inbuf
, sizeof(inbuf
)-1, &bytesread
);
99 if(bytesread
) puts(inbuf
);
100 } while (bytesread
&& memcmp(inbuf
, "230 ", 4));
102 ret
= rocksock_readline(psock
, inbuf
, sizeof(inbuf
)-1, &bytesread
);
104 if(bytesread
) puts(inbuf
);
106 rocksock_disconnect(psock
);
107 rocksock_clear(psock
);