Fixes
[opsoft.git] / gclib2 / modules / Net / FTP / FTP.cxx
blobed0436e534a822dcbc957f253cd400806a10fb9a
1 /*
2 * (c) Oleg Puchinin 2008
3 * graycardinalster@gmail.com
5 */
7 #if 0
9 #include <gclib2.h>
10 #include <gc_network.h>
11 #include <FTP.h>
12 #include <dns.h>
14 const char * lpsz_typeI = "TYPE I\r\n";
16 FTP::FTP ()
18 init ();
19 m_dataConnection = NULL;
22 FTP::FTP (bool passive)
24 init ();
25 m_dataConnection = NULL;
26 m_passive = passive;
29 FTP::~FTP ()
33 List * FTP::waitReply ()
35 List * Ret;
36 char * S;
38 while (true) {
39 Ret = recvStrings ();
40 S = Ret->last ();
41 if (S[3] != '-')
42 break;
43 Ret->foreach (free);
44 delete Ret;
47 return Ret;
50 int FTP::connect (char * server, uint16_t port)
52 int Ret;
54 if (isIP (server))
55 Ret = Connection::connect (server, port);
56 else
57 Ret = Connection::connect (dns_A (server), port);
59 if (Ret < 0)
60 return Ret;
62 return checkReply (220);
65 int FTP::checkReply (int needle)
67 List * res;
68 char * S;
69 int Ret = 0;
70 int i;
72 res = waitReply ();
73 if (!res)
74 return -1;
76 S = res->last ();
77 if (! S) {
78 delete res;
79 return -1;
82 if (needle && (atoi (S) != needle))
83 Ret = -1;
85 res->foreach (free);
86 delete res;
87 return Ret;
90 int FTP::typeI ()
92 send ((char *) lpsz_typeI, strlen (lpsz_typeI));
93 return checkReply (0);
96 int FTP::login (char * l, char * p)
98 char * m_buf;
99 int count;
100 char * S;
101 int Ret = 0;
103 if (! l || ! p)
104 return -1;
106 m_buf = CNEW (char, 4096);
108 sprintf (m_buf, "USER %s\r\n", l);
109 if (send (m_buf, strlen (m_buf)) < 0) {
110 DROP (m_buf);
111 return -1;
114 if (checkReply (331) < 0) {
115 delete m_buf;
116 return -1;
119 sprintf (m_buf, "PASS %s\r\n", p);
120 if (send (m_buf, strlen (m_buf)) < 0) {
121 DROP (m_buf);
122 return -1;
125 if (checkReply (230)) {
126 delete m_buf;
127 return -1;
130 DROP (m_buf);
131 return Ret;
134 int FTP::pasv ()
138 int FTP::port ()
142 char * FTP::syst ()
146 #endif