|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Author: Philippe Gabriel |
|
15 // A simple test program which uses the statically linked dll "ftpprot.dll" |
|
16 // |
|
17 // |
|
18 |
|
19 // standard example header |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 #include <in_sock.h> |
|
23 #include <ftpprot.h> |
|
24 #include "FTPTEST.H" |
|
25 #include "DEBUG.H" |
|
26 |
|
27 TBuf8<1500> myBuffer; |
|
28 |
|
29 //#define __IPV6_TESTS__ |
|
30 #define __IPV4_TESTS__ |
|
31 |
|
32 class TTest01Params |
|
33 { |
|
34 public: |
|
35 void SetParams(const TDesC& aInetAddr, TUint aPort, const TDesC& aHostName, |
|
36 const TPtrC8& aUserName, const TPtrC8& aPassword, |
|
37 const TPtrC8& aDirectoryPath, const TPtrC8& aFileName); |
|
38 public: |
|
39 TInetAddr iInetAddr; |
|
40 THostName iHostName; |
|
41 TUint iPort; |
|
42 TPtrC8 iUserName; |
|
43 TPtrC8 iPassword; |
|
44 TPtrC8 iDirectoryPath; |
|
45 TPtrC8 iFileName; |
|
46 }; |
|
47 |
|
48 void TTest01Params::SetParams(const TDesC& aInetAddr, TUint aPort, const TDesC& aHostName, |
|
49 const TPtrC8& aUserName, const TPtrC8& aPassword, const TPtrC8& aDirectoryPath, |
|
50 const TPtrC8& aFileName) |
|
51 { |
|
52 iInetAddr.Input(aInetAddr); |
|
53 iInetAddr.SetPort(aPort); |
|
54 iPort = aPort; |
|
55 iHostName = aHostName; |
|
56 iUserName.Set(aUserName); |
|
57 iPassword.Set(aPassword); |
|
58 iDirectoryPath.Set(aDirectoryPath); |
|
59 iFileName.Set(aFileName); |
|
60 } |
|
61 |
|
62 class CFtpTest01 : public CBase, public MFtpProtocolNotifier |
|
63 { |
|
64 public: |
|
65 static CFtpTest01* NewL(); |
|
66 ~CFtpTest01(); |
|
67 void DoTest(); |
|
68 void TestMain(); |
|
69 void ServerPositiveAnswerNotification(const TOpComp aStatus); |
|
70 void ServerXFerNotification(const TOpComp aStatus); |
|
71 void ServerNegativeAnswerNotification(const TOpComp aStatus); |
|
72 void ErrorNotification(const TOpComp aStatus); |
|
73 void ServerMessage(const class TDesC8&); |
|
74 |
|
75 private: |
|
76 void PasvTest(); |
|
77 void ListTest(); |
|
78 void RetrTest(); |
|
79 void StorTest(); |
|
80 void DeleTest(); |
|
81 void MkdTest(); |
|
82 |
|
83 void StartScheduler(); |
|
84 void StopSchedulerIfNecessary(); |
|
85 private: |
|
86 TBool iSchedulerStarted; |
|
87 TTest01Params iParams; |
|
88 CFtpProtocol* iCFtpProtocol; |
|
89 TBool iErrorOccured; |
|
90 }; |
|
91 |
|
92 CFtpTest01* CFtpTest01::NewL() |
|
93 { |
|
94 CFtpTest01* self = new(ELeave) CFtpTest01; |
|
95 CleanupStack::PushL(self); |
|
96 self->iCFtpProtocol = CFtpProtocol::NewL(self); |
|
97 CleanupStack::Pop(self); |
|
98 return self; |
|
99 } |
|
100 |
|
101 CFtpTest01::~CFtpTest01() |
|
102 { |
|
103 delete iCFtpProtocol; |
|
104 } |
|
105 |
|
106 void CFtpTest01::StartScheduler() |
|
107 { |
|
108 iSchedulerStarted=ETrue; |
|
109 CActiveScheduler::Start(); |
|
110 } |
|
111 |
|
112 void CFtpTest01::StopSchedulerIfNecessary() |
|
113 { |
|
114 if(iSchedulerStarted) |
|
115 CActiveScheduler::Stop(); |
|
116 iSchedulerStarted=EFalse; |
|
117 } |
|
118 |
|
119 void CFtpTest01::ErrorNotification(const TOpComp aStatus) |
|
120 { |
|
121 FTPPROTDEBUG1(0xffff,_L("CFtpTest01::ErrorNotification called aStatus:%d\n"),aStatus); |
|
122 (void) aStatus; |
|
123 iErrorOccured = ETrue; |
|
124 StopSchedulerIfNecessary(); |
|
125 } |
|
126 |
|
127 void CFtpTest01::ServerPositiveAnswerNotification(const TOpComp aStatus) |
|
128 { |
|
129 FTPPROTDEBUG1(0xffff,_L("CFtpTest01::ServerPositiveAnswerNotification called aStatus:%d\n"),aStatus); |
|
130 (void) aStatus; |
|
131 StopSchedulerIfNecessary(); |
|
132 } |
|
133 |
|
134 void CFtpTest01::ServerNegativeAnswerNotification(const TOpComp aStatus) |
|
135 { |
|
136 FTPPROTDEBUG1(0xffff,_L("CFtpTest01::ServerNegativeAnswerNotification called aStatus:%d\n"),aStatus); |
|
137 (void) aStatus; |
|
138 StopSchedulerIfNecessary(); |
|
139 } |
|
140 |
|
141 void CFtpTest01::ServerXFerNotification(const TOpComp aStatus) |
|
142 { |
|
143 FTPPROTDEBUG1(0xffff,_L("CFtpTest01::ServerXFerNotification called aStatus:%d\n"),aStatus); |
|
144 (void) aStatus; |
|
145 StopSchedulerIfNecessary(); |
|
146 } |
|
147 |
|
148 void CFtpTest01::ServerMessage(const class TDesC8& /*aMessage*/) |
|
149 { |
|
150 FTPPROTDEBUG(0xffff,_L("CFtpTest01::ServerMessage called\n")); |
|
151 } |
|
152 |
|
153 LOCAL_C void doExampleL() |
|
154 { |
|
155 CActiveScheduler* exampleScheduler=new (ELeave) CActiveScheduler; |
|
156 CleanupStack::PushL(exampleScheduler); |
|
157 CActiveScheduler::Install(exampleScheduler); |
|
158 |
|
159 #ifdef __IPV4_TESTS__ |
|
160 __FTPDebugConsole->Printf(_L("FTP Test 01 (Ipv4) \n\n")); |
|
161 #else |
|
162 __FTPDebugConsole->Printf(_L("FTP Test 01 (Ipv6) \n\n")); |
|
163 #endif |
|
164 |
|
165 __FTPDebugConsole->Printf(_L("statically linked DLL example \n\n")); |
|
166 |
|
167 CFtpTest01* myTest01 = CFtpTest01::NewL(); |
|
168 CleanupStack::PushL(myTest01); |
|
169 myTest01->TestMain(); |
|
170 CleanupStack::PopAndDestroy(myTest01); |
|
171 |
|
172 CleanupStack::PopAndDestroy(exampleScheduler); |
|
173 } |
|
174 |
|
175 void CFtpTest01::TestMain() |
|
176 { |
|
177 #ifdef __IPV6_TESTS__ |
|
178 iParams.SetParams(_L("2001:618:400:6a:2c0:4fff:fe8a:a918"), //params for snus6 |
|
179 21, _L("snus6.intra6"), _L8("karlm"), _L8("karlm"), |
|
180 _L8("/usr/home/karlm"), _L8("test.cpp")); |
|
181 DoTest(); |
|
182 |
|
183 iParams.SetParams(_L("2001:618:400:6a:210:5aff:febf:531"), //params for 6pack6 |
|
184 21, _L("6pack6.intra6"), _L8("anonymous"), _L8("karlm"), |
|
185 _L8("/usr"), _L8("anything")); |
|
186 DoTest(); |
|
187 #endif |
|
188 |
|
189 #ifdef __IPV4_TESTS__ |
|
190 iParams.SetParams(_L("207.46.133.140"), 21, _L("ftp.microsoft.com"), //params for ftp.micorsoft.com |
|
191 _L8("anonymous"), _L8("philippe@symbian.com"), _L8("/peropsys"), |
|
192 _L8("readme.txt")); |
|
193 DoTest(); |
|
194 |
|
195 iParams.SetParams(_L("192.18.99.73"), 21, _L("ftp.sun.com"), //params for ftp.sun.com |
|
196 _L8("anonymous"), _L8("philippe@symbian.com"), _L8("/pub"), |
|
197 _L8("index.html")); |
|
198 DoTest(); |
|
199 |
|
200 #endif |
|
201 // TPtrC DNSName(_L("philippeg_nt")); |
|
202 // TPtrC8 userName(_L8("phil")); |
|
203 |
|
204 // TPtrC8 passwd(_L8("phil")); |
|
205 |
|
206 |
|
207 // TInetAddr myaddr(INET_ADDR(64,12,168,249),21);// ftp.netscape.com |
|
208 // TPtrC DNSName(_L("ftp.netscape.com")); |
|
209 // TPtrC userName(_L("anonymous")); |
|
210 // TPtrC passwd(_L("philippe@symbian.com")); |
|
211 // TInetAddr myaddr(INET_ADDR(209,77,154,25),21);// ftp.insignia.com (home of the braves) |
|
212 // TPtrC DNSName(_L("ftp.insignia.com")); |
|
213 // TPtrC8 userName(_L8("anonymous")); |
|
214 // TPtrC8 passwd(_L8("philippe@symbian.com")); |
|
215 // TPtrC directoryPath(_L("special/ntrigue/")); |
|
216 // TPtrC fileName(_L("read5.txt")); |
|
217 // |
|
218 // TInetAddr myaddr(INET_ADDR(155,198,143,16),21);// ftp.radian.ee.ic.ac.uk |
|
219 // TPtrC DNSName(_L("radian.ee.ic.ac.uk")); |
|
220 // |
|
221 __FTPDebugConsole->Printf(_L("Finished tests\n")); |
|
222 } |
|
223 |
|
224 void CFtpTest01::DoTest() |
|
225 { |
|
226 iErrorOccured = EFalse; |
|
227 iCFtpProtocol->Connect(iParams.iInetAddr); //Just do a normal connect. |
|
228 StartScheduler(); |
|
229 if(iErrorOccured) |
|
230 return; |
|
231 |
|
232 //Removed temporarily due to problems with host resolution |
|
233 // iCFtpProtocol->Quit(); |
|
234 // StartScheduler(); |
|
235 |
|
236 // iCFtpProtocol->Connect(iParams.iHostName, iParams.iPort); //Now try using a host name to test resolver. |
|
237 // StartScheduler(); |
|
238 // if(iErrorOccured) |
|
239 // return; |
|
240 |
|
241 iCFtpProtocol->Help(); |
|
242 StartScheduler(); |
|
243 iCFtpProtocol->User(iParams.iUserName); |
|
244 StartScheduler(); |
|
245 iCFtpProtocol->Pass(iParams.iPassword); |
|
246 StartScheduler(); |
|
247 |
|
248 PasvTest(); |
|
249 __FTPDebugConsole->Printf(_L("FTP PasvTest \n")); |
|
250 |
|
251 ListTest(); |
|
252 __FTPDebugConsole->Printf(_L("FTP ListTest \n")); |
|
253 |
|
254 RetrTest(); |
|
255 __FTPDebugConsole->Printf(_L("FTP RetrTest \n")); |
|
256 |
|
257 StorTest(); |
|
258 __FTPDebugConsole->Printf(_L("FTP StorTest \n")); |
|
259 |
|
260 DeleTest(); |
|
261 __FTPDebugConsole->Printf(_L("FTP DeleTest \n")); |
|
262 |
|
263 MkdTest(); |
|
264 __FTPDebugConsole->Printf(_L("FTP MkdTest \n")); |
|
265 |
|
266 //QUIT// |
|
267 |
|
268 iCFtpProtocol->Quit(); |
|
269 StartScheduler(); |
|
270 } |
|
271 |
|
272 |
|
273 void CFtpTest01::PasvTest() |
|
274 { |
|
275 iCFtpProtocol->Pasv(); |
|
276 StartScheduler(); |
|
277 } |
|
278 |
|
279 void CFtpTest01::ListTest() |
|
280 { |
|
281 iCFtpProtocol->Port(); |
|
282 StartScheduler(); |
|
283 iCFtpProtocol->RecvBuffer(&myBuffer); |
|
284 iCFtpProtocol->List(iParams.iDirectoryPath); |
|
285 StartScheduler(); |
|
286 } |
|
287 |
|
288 void CFtpTest01::RetrTest() |
|
289 { |
|
290 iCFtpProtocol->Port(); |
|
291 StartScheduler(); |
|
292 iCFtpProtocol->Cwd(iParams.iDirectoryPath); |
|
293 StartScheduler(); |
|
294 iCFtpProtocol->RecvBuffer(&myBuffer); |
|
295 iCFtpProtocol->Retr(iParams.iFileName); |
|
296 StartScheduler(); |
|
297 } |
|
298 |
|
299 void CFtpTest01::StorTest() |
|
300 { |
|
301 myBuffer = _L8("This is a test file:\n\ |
|
302 Sous le Pont Mirabeau coule la Seine\n\ |
|
303 et nos amours, faut il qu'il m'en souvienne\n\ |
|
304 la joie venait toujours apres la peine\n"); |
|
305 iCFtpProtocol->Port(); |
|
306 StartScheduler(); |
|
307 iCFtpProtocol->SendBuffer(&myBuffer); |
|
308 iCFtpProtocol->Stor(_L8("ftptst01.txt")); |
|
309 StartScheduler(); |
|
310 } |
|
311 |
|
312 void CFtpTest01::DeleTest() |
|
313 { |
|
314 iCFtpProtocol->Dele(_L8("ftptst01.txt")); |
|
315 StartScheduler(); |
|
316 } |
|
317 |
|
318 void CFtpTest01::MkdTest() |
|
319 { |
|
320 iCFtpProtocol->Cwd(iParams.iDirectoryPath); |
|
321 StartScheduler(); |
|
322 iCFtpProtocol->Mkd(_L8("test")); |
|
323 StartScheduler(); |
|
324 } |