|
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 "DEBUG.H" |
|
21 #include <e32base.h> |
|
22 #include <es_sock.h> |
|
23 #include <in_sock.h> |
|
24 #include <ftpsess.h> |
|
25 #include "FTPTEST.H" |
|
26 |
|
27 TBuf8<955> myBuffer8; |
|
28 TBuf<2000> myBuffer; |
|
29 TInt total; |
|
30 |
|
31 #define __CONSOLE_OUTPUT__ |
|
32 |
|
33 #define __FILERETR_TESTS__ |
|
34 //#define __IPV4_TESTS__ |
|
35 //#define __IPV6_TESTS__ |
|
36 |
|
37 class TFtpTest02Params |
|
38 { |
|
39 public: |
|
40 void SetParams(const TDesC& aInetAddr, TUint aPort, const TDesC& aHostName, |
|
41 const TDesC8& aUserName, const TDesC8& aPassword, const TDesC8& aDirectoryPath, |
|
42 const TDesC8& aRemoteFileName, const TDesC& aLocalFileName); |
|
43 public: |
|
44 TInetAddr iInetAddr; |
|
45 TUint iPort; |
|
46 THostName iHostName; |
|
47 TPtrC8 iUserName; |
|
48 TPtrC8 iPassword; |
|
49 TPtrC8 iDirectoryPath; |
|
50 TPtrC8 iRemoteFileName; |
|
51 TPtrC iLocalFileName; |
|
52 }; |
|
53 |
|
54 void TFtpTest02Params::SetParams(const TDesC& aInetAddr, TUint aPort, const TDesC& aHostName, |
|
55 const TDesC8& aUserName, const TDesC8& aPassword, const TDesC8& aDirectoryPath, |
|
56 const TDesC8& aRemoteFileName, const TDesC& aLocalFileName) |
|
57 { |
|
58 iInetAddr.Input(aInetAddr); |
|
59 iInetAddr.SetPort(aPort); |
|
60 iPort=aPort; |
|
61 iHostName=aHostName; |
|
62 iUserName.Set(aUserName); |
|
63 iDirectoryPath.Set(aDirectoryPath); |
|
64 iPassword.Set(aPassword); |
|
65 iRemoteFileName.Set(aRemoteFileName); |
|
66 iLocalFileName.Set(aLocalFileName); |
|
67 } |
|
68 |
|
69 // |
|
70 |
|
71 class CFtpTest02 : public CBase, public MFtpSessionNotifier |
|
72 { |
|
73 public: |
|
74 static CFtpTest02* NewL(); |
|
75 ~CFtpTest02(); |
|
76 void DoTest(); |
|
77 void TestMain(); |
|
78 void StartScheduler(); |
|
79 void StopSchedulerIfNecessary(); |
|
80 |
|
81 void Complete(void); |
|
82 // Operation completed, more data to follow |
|
83 void MoreData(void); |
|
84 // Transfer Progress report |
|
85 void TransferProgress(TUint aProgress); |
|
86 // User canceled ongoing operation |
|
87 void Cancel(void); |
|
88 // Peer reset the connection |
|
89 void ConnReset(void); |
|
90 // Connection error |
|
91 void ConnectionError(TOpComp aTConnectionError); |
|
92 // FTP server does not implement the operation requested |
|
93 void OperationNotSupported(void); |
|
94 // Local File system error |
|
95 void LocalFileSystemError(TOpComp aTLocalFileSystemError); |
|
96 // Remote File system error |
|
97 void RemoteFileSystemError(TOpComp aTRemoteFileSystemError); |
|
98 // Not specified yet |
|
99 void EUnknownError(); |
|
100 // Message reported by server |
|
101 void ServerMessage(const TDesC8&); |
|
102 |
|
103 void ListTest(); |
|
104 void RestartTest(); |
|
105 void FailedRetrievalTest(); |
|
106 void FailedRetrievalTestOverwrite(); |
|
107 void RetriveveTestOverwrite(); |
|
108 void RenameTest(); |
|
109 void DeleteFileTest(); |
|
110 void StoreTest(); |
|
111 void DirectoryTest(); |
|
112 |
|
113 protected: |
|
114 CFtpTest02(); |
|
115 private: |
|
116 CFTPSession* iCFTPSession; |
|
117 TFtpTest02Params iTestParams; |
|
118 TBool iSchedulerStarted; |
|
119 }; |
|
120 |
|
121 CFtpTest02* CFtpTest02::NewL() |
|
122 { |
|
123 CFtpTest02* self = new(ELeave) CFtpTest02(); |
|
124 CleanupStack::PushL(self); |
|
125 self->iCFTPSession = CFTPSession::NewL(self); |
|
126 CleanupStack::Pop(self); |
|
127 return self; |
|
128 } |
|
129 |
|
130 CFtpTest02::CFtpTest02() |
|
131 {} |
|
132 |
|
133 CFtpTest02::~CFtpTest02() |
|
134 { |
|
135 delete iCFTPSession; |
|
136 } |
|
137 |
|
138 void CFtpTest02::StartScheduler() |
|
139 { |
|
140 iSchedulerStarted=ETrue; |
|
141 CActiveScheduler::Start(); |
|
142 } |
|
143 |
|
144 void CFtpTest02::StopSchedulerIfNecessary() |
|
145 { |
|
146 if(iSchedulerStarted) |
|
147 CActiveScheduler::Stop(); |
|
148 iSchedulerStarted=EFalse; |
|
149 } |
|
150 |
|
151 void CFtpTest02::ServerMessage(const TDesC8& aMessage) |
|
152 { |
|
153 myBuffer.Copy(aMessage); |
|
154 #ifdef __CONSOLE_OUTPUT__ |
|
155 __FTPDebugConsole->Write(myBuffer); |
|
156 #endif |
|
157 |
|
158 FTPPROTDEBUG(0xffff,myBuffer); |
|
159 } |
|
160 |
|
161 void CFtpTest02::TransferProgress(TUint aProgress) |
|
162 { |
|
163 total += aProgress; |
|
164 #ifdef __CONSOLE_OUTPUT__ |
|
165 __FTPDebugConsole->Printf(_L("CFtpTest02::TransferProgress total:>%d< Packet:>%d<\n"),total,aProgress); |
|
166 #endif |
|
167 |
|
168 FTPPROTDEBUG3(0xffff, _L("CFtpTest02::TransferProgress total:>%d< Packet:>%d<\n"),total,aProgress); |
|
169 |
|
170 } |
|
171 |
|
172 void CFtpTest02::Complete(void) |
|
173 { |
|
174 #ifdef __CONSOLE_OUTPUT__ |
|
175 __FTPDebugConsole->Write(_L("CFtpTest02::Complete\n")); |
|
176 #endif |
|
177 |
|
178 FTPPROTDEBUG(0xffff, _L("CFtpTest02::Complete\n")); |
|
179 StopSchedulerIfNecessary(); |
|
180 } |
|
181 |
|
182 void CFtpTest02::Cancel(void){} |
|
183 |
|
184 void CFtpTest02::ConnReset(void) |
|
185 { |
|
186 #ifdef __CONSOLE_OUTPUT__ |
|
187 __FTPDebugConsole->Write(_L("CFtpTest02::ConnReset\n")); |
|
188 #endif |
|
189 |
|
190 FTPPROTDEBUG(0xffff, _L("CFtpTest02::ConnReset\n")); |
|
191 StopSchedulerIfNecessary(); |
|
192 } |
|
193 |
|
194 void CFtpTest02::ConnectionError(TOpComp /*aTConnectionError*/) |
|
195 { |
|
196 #ifdef __CONSOLE_OUTPUT__ |
|
197 __FTPDebugConsole->Write(_L("CFtpTest02::ConnectionError\n")); |
|
198 #endif |
|
199 |
|
200 FTPPROTDEBUG(0xffff, _L("CFtpTest02::ConnectionError\n")); |
|
201 StopSchedulerIfNecessary(); |
|
202 } |
|
203 |
|
204 void CFtpTest02::OperationNotSupported(void){} |
|
205 |
|
206 void CFtpTest02::LocalFileSystemError(TOpComp /*aTLocalFileSystemError*/) |
|
207 { |
|
208 #ifdef __CONSOLE_OUTPUT__ |
|
209 __FTPDebugConsole->Write(_L("CFtpTest02::LocalFileSystemError\n")); |
|
210 #endif |
|
211 |
|
212 FTPPROTDEBUG(0xffff, _L("CFtpTest02::LocalFileSystemError\n")); |
|
213 StopSchedulerIfNecessary(); |
|
214 } |
|
215 |
|
216 void CFtpTest02::RemoteFileSystemError(TOpComp /*aTRemoteFileSystemError*/) |
|
217 { |
|
218 StopSchedulerIfNecessary(); |
|
219 #ifdef __CONSOLE_OUTPUT__ |
|
220 __FTPDebugConsole->Write(_L("CFtpTest02::RemoteFileSystemError\n")); |
|
221 #endif |
|
222 |
|
223 FTPPROTDEBUG(0xffff, _L("CFtpTest02::RemoteFileSystemError\n")); |
|
224 } |
|
225 |
|
226 void CFtpTest02::EUnknownError(void) |
|
227 { |
|
228 #ifdef __CONSOLE_OUTPUT__ |
|
229 __FTPDebugConsole->Write(_L("Test02Notifier::EUnknownError\n")); |
|
230 #endif |
|
231 |
|
232 FTPPROTDEBUG(0xffff, _L("Test02Notifier::EUnknownError\n")); |
|
233 StopSchedulerIfNecessary(); |
|
234 } |
|
235 |
|
236 void CFtpTest02::MoreData(void) |
|
237 { |
|
238 #ifdef __CONSOLE_OUTPUT__ |
|
239 __FTPDebugConsole->Write(_L("CFtpTest02::Notification called EPacketReceived\n")); |
|
240 __FTPDebugConsole->Write(_L("----------Packet from DTP Channel---------\n")); |
|
241 __FTPDebugConsole->Write(myBuffer); |
|
242 __FTPDebugConsole->Write(_L("\n----------End of Packet from DTP Channel---------\n")); |
|
243 #endif |
|
244 |
|
245 FTPPROTDEBUG(0xffff,_L("CFtpTest02::Notification called EPacketReceived\n")); |
|
246 FTPPROTDEBUG(0xffff,_L("----------Packet from DTP Channel---------\n")); |
|
247 FTPPROTDEBUG(0xffff,myBuffer); |
|
248 FTPPROTDEBUG(0xffff,_L("\n----------End of Packet from DTP Channel---------\n")); |
|
249 |
|
250 iCFTPSession->ListDirectory(_L8(""),myBuffer8); |
|
251 return; |
|
252 } |
|
253 |
|
254 |
|
255 |
|
256 LOCAL_C void doExampleL() |
|
257 { |
|
258 |
|
259 CActiveScheduler* exampleScheduler=new (ELeave) CActiveScheduler; |
|
260 CleanupStack::PushL(exampleScheduler); |
|
261 CActiveScheduler::Install(exampleScheduler); |
|
262 |
|
263 CFtpTest02* myFtpTest02 = CFtpTest02::NewL(); |
|
264 CleanupStack::PushL(myFtpTest02); |
|
265 |
|
266 #ifdef __IPV4_TESTS__ |
|
267 __FTPDebugConsole->Printf(_L("FTP Test 02 Ipv4 \n\n")); |
|
268 #else |
|
269 #ifdef __FILERETR_TESTS__ |
|
270 __FTPDebugConsole->Printf(_L("FTP Test 02 File retreive \n\n")); |
|
271 #else |
|
272 __FTPDebugConsole->Printf(_L("FTP Test 02 Ipv6 \n\n")); |
|
273 #endif |
|
274 #endif |
|
275 |
|
276 __FTPDebugConsole->Printf(_L("FTP Session client \n\n")); |
|
277 |
|
278 myFtpTest02->TestMain(); |
|
279 |
|
280 __FTPDebugConsole->Printf(_L("Finished test\n")); |
|
281 |
|
282 CleanupStack::PopAndDestroy(myFtpTest02); |
|
283 CleanupStack::PopAndDestroy(exampleScheduler); |
|
284 } |
|
285 |
|
286 void CFtpTest02::TestMain() |
|
287 { |
|
288 #ifdef __IPV4_TESTS__ |
|
289 iTestParams.SetParams(_L("207.46.133.140"), 21, _L("ftp.microsoft.com"), //params for microsoft ftp site |
|
290 _L8("anonymous"), _L8("philippe@symbian.com"), _L8("misc"), _L8("index.txt"), |
|
291 _L("index.txt")); |
|
292 DoTest(); |
|
293 |
|
294 iTestParams.SetParams(_L("192.18.99.73"), 21, _L("ftp.sun.com"), |
|
295 _L8("anonymous"), _L8("karl.mcdowall@symbian.com"), _L8("/"), _L8("swec.dat"), |
|
296 _L("swec.dat")); |
|
297 DoTest(); |
|
298 #endif |
|
299 |
|
300 #ifdef __FILERETR_TESTS__ |
|
301 iTestParams.SetParams(_L("10.16.113.6"), 21, _L("ftp-images"), |
|
302 _L8("roms"), _L8("integrator"), _L8("/"), _L8("psdagt_udeb.htm"), |
|
303 _L("psdagt_udeb.htm")); |
|
304 |
|
305 iCFTPSession->Connect(iTestParams.iInetAddr,iTestParams.iUserName, //Login using passive mode |
|
306 iTestParams.iPassword,CFTPSession::Epassive); |
|
307 StartScheduler(); |
|
308 |
|
309 RetriveveTestOverwrite(); |
|
310 FailedRetrievalTestOverwrite(); |
|
311 FailedRetrievalTest(); |
|
312 |
|
313 iCFTPSession->Close(); |
|
314 StartScheduler(); |
|
315 #endif |
|
316 |
|
317 #ifdef __IPV6_TESTS__ |
|
318 iTestParams.SetParams(_L("2001:618:400:6a:2c0:4fff:fe8a:a918"), //params for snus6 |
|
319 21, _L("snus6.intra6"), _L8("karlm"), _L8("karlm"), |
|
320 _L8("/usr/home/karlm"), _L8("test.cpp"), _L("test.cpp")); |
|
321 DoTest(); |
|
322 |
|
323 iTestParams.SetParams(_L("2001:618:400:6a:210:5aff:febf:531"), //params for 6pack6 |
|
324 21, _L("6pack6.intra6"), _L8("anonymous"), _L8("karlm"), |
|
325 _L8("/usr"), _L8("anything"), _L("anything")); |
|
326 DoTest(); |
|
327 #endif |
|
328 } |
|
329 |
|
330 void CFtpTest02::DoTest() |
|
331 { |
|
332 //Removed teporarily due to problem with host resolution |
|
333 // iCFTPSession->Connect(iTestParams.iHostName,iTestParams.iUserName, //Login using hostname |
|
334 // iTestParams.iPassword,CFTPSession::EActive,iTestParams.iPort); |
|
335 // StartScheduler(); |
|
336 // iCFTPSession->Close(); |
|
337 // StartScheduler(); |
|
338 |
|
339 iCFTPSession->Connect(iTestParams.iInetAddr,iTestParams.iUserName, //Login using Active mode |
|
340 iTestParams.iPassword,CFTPSession::EActive); |
|
341 StartScheduler(); |
|
342 iCFTPSession->Close(); |
|
343 StartScheduler(); |
|
344 |
|
345 iCFTPSession->Connect(iTestParams.iInetAddr,iTestParams.iUserName, //Login using passive mode |
|
346 iTestParams.iPassword,CFTPSession::Epassive); |
|
347 StartScheduler(); |
|
348 |
|
349 iCFTPSession->ChangeDirectory(iTestParams.iDirectoryPath); //Move to appropriate directory. |
|
350 StartScheduler(); |
|
351 |
|
352 ListTest(); |
|
353 RetriveveTestOverwrite(); |
|
354 FailedRetrievalTest(); |
|
355 FailedRetrievalTestOverwrite(); |
|
356 RenameTest(); |
|
357 DeleteFileTest(); |
|
358 StoreTest(); |
|
359 RestartTest(); |
|
360 DirectoryTest(); |
|
361 |
|
362 |
|
363 iCFTPSession->Close(); |
|
364 StartScheduler(); |
|
365 |
|
366 } |
|
367 |
|
368 void CFtpTest02::ListTest() |
|
369 { |
|
370 iCFTPSession->ListDirectory(_L8("."),myBuffer8); |
|
371 StartScheduler(); |
|
372 } |
|
373 |
|
374 void CFtpTest02::RestartTest() |
|
375 { |
|
376 // Note: Restart is a synchronous function |
|
377 iCFTPSession->Restart(50000); |
|
378 } |
|
379 |
|
380 void CFtpTest02::RetriveveTestOverwrite() |
|
381 { |
|
382 total =0; |
|
383 iCFTPSession->Retrieve(iTestParams.iRemoteFileName,iTestParams.iLocalFileName, |
|
384 CFTPSession::EOverwrite,CFTPSession::EBinary,CFTPSession::EStream); |
|
385 StartScheduler(); |
|
386 } |
|
387 |
|
388 void CFtpTest02::FailedRetrievalTest() |
|
389 { |
|
390 iCFTPSession->Retrieve(_L8("NoExist"),_L("NoExist"),CFTPSession::ENoOverwrite,CFTPSession::EBinary,CFTPSession::EStream); |
|
391 StartScheduler(); |
|
392 } |
|
393 |
|
394 void CFtpTest02::FailedRetrievalTestOverwrite() |
|
395 { |
|
396 iCFTPSession->Retrieve(_L8("NoExist"),iTestParams.iLocalFileName,CFTPSession::EOverwrite,CFTPSession::EBinary,CFTPSession::EStream); |
|
397 StartScheduler(); |
|
398 } |
|
399 |
|
400 void CFtpTest02::DeleteFileTest() |
|
401 { |
|
402 iCFTPSession->DeleteFile(iTestParams.iRemoteFileName); |
|
403 StartScheduler(); |
|
404 } |
|
405 |
|
406 void CFtpTest02::StoreTest() |
|
407 { |
|
408 iCFTPSession->Store(iTestParams.iLocalFileName,iTestParams.iRemoteFileName, |
|
409 EFalse, CFTPSession::EBinary,CFTPSession::EStream); |
|
410 StartScheduler(); |
|
411 } |
|
412 |
|
413 void CFtpTest02::RenameTest() |
|
414 { |
|
415 iCFTPSession->RenameFile(iTestParams.iRemoteFileName, _L8("tempName")); |
|
416 StartScheduler(); |
|
417 iCFTPSession->RenameFile(_L8("tempName"), iTestParams.iRemoteFileName); |
|
418 StartScheduler(); |
|
419 } |
|
420 |
|
421 void CFtpTest02::DirectoryTest() |
|
422 { |
|
423 iCFTPSession->CreateDirectory(_L8("TestDir0")); |
|
424 StartScheduler(); |
|
425 iCFTPSession->DeleteDirectory(_L8("TestDir1")); |
|
426 StartScheduler(); |
|
427 } |
|
428 |
|
429 //Old IP4 ftp sites. Might be worth keeping as a record in case the ones currently being used |
|
430 //stop working. |
|
431 // |
|
432 // TInetAddr myaddr(INET_ADDR(207,200,71,59),21);// ftp.netscape.com |
|
433 // TPtrC DNSName(_L("ftp.netscape.com")); |
|
434 // TPtrC userName(_L("anonymous")); |
|
435 // TPtrC passwd(_L("philippe@symbian.com")); |
|
436 // TPtrC directoryPath(_L("pub/communicator/extras/import/eudora")); |
|
437 // TPtrC fileName(_L("Readme.txt")); |
|
438 // |
|
439 // TInetAddr myaddr(INET_ADDR(209,77,154,25),21);// ftp.insignia.com (home of the braves) |
|
440 // TPtrC DNSName(_L("ftp.insignia.com")); |
|
441 // TPtrC userName(_L("anonymous")); |
|
442 // TPtrC passwd(_L("philippe@symbian.com")); |
|
443 // TPtrC directoryPath(_L("special/ntrigue/")); |
|
444 // TPtrC fileName(_L("read4a.txt")); |
|
445 // |
|
446 // TInetAddr myaddr(INET_ADDR(194,129,2,201),21);// sparky |
|
447 // TPtrC DNSName(_L("sparky")); |
|
448 // TPtrC userName(_L("philippe")); |
|
449 // TPtrC passwd(_L("massilia")); |
|
450 // TPtrC directoryPath(_L("ftptest")); |
|
451 // TPtrC fileName(_L("testfile.bin")); |
|
452 // TPtrC fileName(_L("map.gif")); |
|
453 // TPtrC localFile(_L("motodemo.zip")); |
|
454 // |