Avoid using uninitialized variables
[reactos.git] / cis / ReactOS.CustomRevisionAction / FtpClient.cs
1 using System;
2 using System.Net;
3 using System.IO;
4 using System.Text;
5 using System.Net.Sockets;
6 using System.Diagnostics;
7 using System.Runtime.Remoting;
8 using System.Runtime.Remoting.Messaging;
9
10 /*
11 * FTP Client library in C#
12 * Author: Jaimon Mathew
13 * mailto:jaimonmathew@rediffmail.com
14 * http://www.csharphelp.com/archives/archive9.html
15 *
16 * Addapted for use by Dan Glass 07/03/03
17 */
18
19
20 namespace ReactOS.CustomRevisionAction
21 {
22
23 public class FtpClient
24 {
25
26 public class FtpException : Exception
27 {
28 public FtpException(string message) : base(message){}
29 public FtpException(string message, Exception innerException) : base(message,innerException){}
30 }
31
32 private static int BUFFER_SIZE = 512;
33 private static Encoding ASCII = Encoding.ASCII;
34
35 private bool verboseDebugging = false;
36
37 // defaults
38 private string server = "localhost";
39 private string remotePath = ".";
40 private string username = "anonymous";
41 private string password = "anonymous@anonymous.net";
42 private string message = null;
43 private string result = null;
44
45 private int port = 21;
46 private int bytes = 0;
47 private int resultCode = 0;
48
49 private bool loggedin = false;
50 private bool binMode = false;
51
52 private Byte[] buffer = new Byte[BUFFER_SIZE];
53 private Socket clientSocket = null;
54
55 private int timeoutSeconds = 10;
56
57 /// <summary>
58 /// Default contructor
59 /// </summary>
60 public FtpClient()
61 {
62 }
63 /// <summary>
64 ///
65 /// </summary>
66 /// <param name="server"></param>
67 /// <param name="username"></param>
68 /// <param name="password"></param>
69 public FtpClient(string server, string username, string password)
70 {
71 this.server = server;
72 this.username = username;
73 this.password = password;
74 }
75 /// <summary>
76 ///
77 /// </summary>
78 /// <param name="server"></param>
79 /// <param name="username"></param>
80 /// <param name="password"></param>
81 /// <param name="timeoutSeconds"></param>
82 /// <param name="port"></param>
83 public FtpClient(string server, string username, string password, int timeoutSeconds, int port)
84 {
85 this.server = server;
86 this.username = username;
87 this.password = password;
88 this.timeoutSeconds = timeoutSeconds;
89 this.port = port;
90 }
91
92 /// <summary>
93 /// Display all communications to the debug log
94 /// </summary>
95 public bool VerboseDebugging
96 {
97 get
98 {
99 return this.verboseDebugging;
100 }
101 set
102 {
103 this.verboseDebugging = value;
104 }
105 }
106 /// <summary>
107 /// Remote server port. Typically TCP 21
108 /// </summary>
109 public int Port
110 {
111 get
112 {
113 return this.port;
114 }
115 set
116 {
117 this.port = value;
118 }
119 }
120 /// <summary>
121 /// Timeout waiting for a response from server, in seconds.
122 /// </summary>
123 public int Timeout
124 {
125 get
126 {
127 return this.timeoutSeconds;
128 }
129 set
130 {
131 this.timeoutSeconds = value;
132 }
133 }
134 /// <summary>
135 /// Gets and Sets the name of the FTP server.
136 /// </summary>
137 /// <returns></returns>
138 public string Server
139 {
140 get
141 {
142 return this.server;
143 }
144 set
145 {
146 this.server = value;
147 }
148 }
149 /// <summary>
150 /// Gets and Sets the port number.
151 /// </summary>
152 /// <returns></returns>
153 public int RemotePort
154 {
155 get
156 {
157 return this.port;
158 }
159 set
160 {
161 this.port = value;
162 }
163 }
164 /// <summary>
165 /// GetS and Sets the remote directory.
166 /// </summary>
167 public string RemotePath
168 {
169 get
170 {
171 return this.remotePath;
172 }
173 set
174 {
175 this.remotePath = value;
176 }
177
178 }
179 /// <summary>
180 /// Gets and Sets the username.
181 /// </summary>
182 public string Username
183 {
184 get
185 {
186 return this.username;
187 }
188 set
189 {
190 this.username = value;
191 }
192 }
193 /// <summary>
194 /// Gets and Set the password.
195 /// </summary>
196 public string Password
197 {
198 get
199 {
200 return this.password;
201 }
202 set
203 {
204 this.password = value;
205 }
206 }
207
208 /// <summary>
209 /// If the value of mode is true, set binary mode for downloads, else, Ascii mode.
210 /// </summary>
211 public bool BinaryMode
212 {
213 get
214 {
215 return this.binMode;
216 }
217 set
218 {
219 if ( this.binMode == value ) return;
220
221 if ( value )
222 sendCommand("TYPE I");
223
224 else
225 sendCommand("TYPE A");
226
227 if ( this.resultCode != 200 ) throw new FtpException(result.Substring(4));
228 }
229 }
230 /// <summary>
231 /// Login to the remote server.
232 /// </summary>
233 public void Login()
234 {
235 if ( this.loggedin ) this.Close();
236
237 Debug.WriteLine("Opening connection to " + this.server, "FtpClient" );
238
239 IPAddress addr = null;
240 IPEndPoint ep = null;
241
242 try
243 {
244 this.clientSocket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
245 addr = Dns.Resolve(this.server).AddressList[0];
246 ep = new IPEndPoint( addr, this.port );
247 this.clientSocket.Connect(ep);
248 }
249 catch(Exception ex)
250 {
251 // doubtfull
252 if ( this.clientSocket != null && this.clientSocket.Connected ) this.clientSocket.Close();
253
254 throw new FtpException("Couldn't connect to remote server",ex);
255 }
256
257 this.readResponse();
258
259 if(this.resultCode != 220)
260 {
261 this.Close();
262 throw new FtpException(this.result.Substring(4));
263 }
264
265 this.sendCommand( "USER " + username );
266
267 if( !(this.resultCode == 331 || this.resultCode == 230) )
268 {
269 this.cleanup();
270 throw new FtpException(this.result.Substring(4));
271 }
272
273 if( this.resultCode != 230 )
274 {
275 this.sendCommand( "PASS " + password );
276
277 if( !(this.resultCode == 230 || this.resultCode == 202) )
278 {
279 this.cleanup();
280 throw new FtpException(this.result.Substring(4));
281 }
282 }
283
284 this.loggedin = true;
285
286 Debug.WriteLine( "Connected to " + this.server, "FtpClient" );
287
288 this.ChangeDir(this.remotePath);
289 }
290
291 /// <summary>
292 /// Close the FTP connection.
293 /// </summary>
294 public void Close()
295 {
296 Debug.WriteLine("Closing connection to " + this.server, "FtpClient" );
297
298 if( this.clientSocket != null )
299 {
300 this.sendCommand("QUIT");
301 }
302
303 this.cleanup();
304 }
305
306 /// <summary>
307 /// Return a string array containing the remote directory's file list.
308 /// </summary>
309 /// <returns></returns>
310 public string[] GetFileList()
311 {
312 return this.GetFileList("*.*");
313 }
314
315 /// <summary>
316 /// Return a string array containing the remote directory's file list.
317 /// </summary>
318 /// <param name="mask"></param>
319 /// <returns></returns>
320 public string[] GetFileList(string mask)
321 {
322 if ( !this.loggedin ) this.Login();
323
324 Socket cSocket = createDataSocket();
325
326 this.sendCommand("NLST " + mask);
327
328 if(!(this.resultCode == 150 || this.resultCode == 125)) throw new FtpException(this.result.Substring(4));
329
330 this.message = "";
331
332 DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);
333
334 while( timeout > DateTime.Now )
335 {
336 int bytes = cSocket.Receive(buffer, buffer.Length, 0);
337 this.message += ASCII.GetString(buffer, 0, bytes);
338
339 if ( bytes < this.buffer.Length ) break;
340 }
341
342 string[] msg = this.message.Replace("\r","").Split('\n');
343
344 cSocket.Close();
345
346 if ( this.message.IndexOf( "No such file or directory" ) != -1 )
347 msg = new string[]{};
348
349 this.readResponse();
350
351 if ( this.resultCode != 226 )
352 msg = new string[]{};
353 // throw new FtpException(result.Substring(4));
354
355 return msg;
356 }
357
358 public bool DirectoryExists(string directory)
359 {
360 try
361 {
362 ChangeDir(directory);
363 ChangeDir("..");
364 return true;
365 }
366 catch (FtpException)
367 {
368 return false;
369 }
370 }
371
372 /// <summary>
373 /// Return the size of a file.
374 /// </summary>
375 /// <param name="fileName"></param>
376 /// <returns></returns>
377 public long GetFileSize(string fileName)
378 {
379 if ( !this.loggedin ) this.Login();
380
381 this.sendCommand("SIZE " + fileName);
382 long size=0;
383
384 if ( this.resultCode == 213 )
385 size = long.Parse(this.result.Substring(4));
386
387 else
388 throw new FtpException(this.result.Substring(4));
389
390 return size;
391 }
392
393
394 /// <summary>
395 /// Download a file to the Assembly's local directory,
396 /// keeping the same file name.
397 /// </summary>
398 /// <param name="remFileName"></param>
399 public void Download(string remFileName)
400 {
401 this.Download(remFileName,"",false);
402 }
403
404 /// <summary>
405 /// Download a remote file to the Assembly's local directory,
406 /// keeping the same file name, and set the resume flag.
407 /// </summary>
408 /// <param name="remFileName"></param>
409 /// <param name="resume"></param>
410 public void Download(string remFileName,Boolean resume)
411 {
412 this.Download(remFileName,"",resume);
413 }
414
415 /// <summary>
416 /// Download a remote file to a local file name which can include
417 /// a path. The local file name will be created or overwritten,
418 /// but the path must exist.
419 /// </summary>
420 /// <param name="remFileName"></param>
421 /// <param name="locFileName"></param>
422 public void Download(string remFileName,string locFileName)
423 {
424 this.Download(remFileName,locFileName,false);
425 }
426
427 /// <summary>
428 /// Download a remote file to a local file name which can include
429 /// a path, and set the resume flag. The local file name will be
430 /// created or overwritten, but the path must exist.
431 /// </summary>
432 /// <param name="remFileName"></param>
433 /// <param name="locFileName"></param>
434 /// <param name="resume"></param>
435 public void Download(string remFileName,string locFileName,Boolean resume)
436 {
437 if ( !this.loggedin ) this.Login();
438
439 this.BinaryMode = true;
440
441 Debug.WriteLine("Downloading file " + remFileName + " from " + server + "/" + remotePath, "FtpClient" );
442
443 if (locFileName.Equals(""))
444 {
445 locFileName = remFileName;
446 }
447
448 FileStream output = null;
449
450 if ( !File.Exists(locFileName) )
451 output = File.Create(locFileName);
452
453 else
454 output = new FileStream(locFileName,FileMode.Open);
455
456 Socket cSocket = createDataSocket();
457
458 long offset = 0;
459
460 if ( resume )
461 {
462 offset = output.Length;
463
464 if ( offset > 0 )
465 {
466 this.sendCommand( "REST " + offset );
467 if ( this.resultCode != 350 )
468 {
469 //Server dosnt support resuming
470 offset = 0;
471 Debug.WriteLine("Resuming not supported:" + result.Substring(4), "FtpClient" );
472 }
473 else
474 {
475 Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );
476 output.Seek( offset, SeekOrigin.Begin );
477 }
478 }
479 }
480
481 this.sendCommand("RETR " + remFileName);
482
483 if ( this.resultCode != 150 && this.resultCode != 125 )
484 {
485 throw new FtpException(this.result.Substring(4));
486 }
487
488 DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);
489
490 while ( timeout > DateTime.Now )
491 {
492 this.bytes = cSocket.Receive(buffer, buffer.Length, 0);
493 output.Write(this.buffer,0,this.bytes);
494
495 if ( this.bytes <= 0)
496 {
497 break;
498 }
499 }
500
501 output.Close();
502
503 if ( cSocket.Connected ) cSocket.Close();
504
505 this.readResponse();
506
507 if( this.resultCode != 226 && this.resultCode != 250 )
508 throw new FtpException(this.result.Substring(4));
509 }
510
511
512 /// <summary>
513 /// Upload a file.
514 /// </summary>
515 /// <param name="fileName"></param>
516 public void Upload(string fileName)
517 {
518 this.Upload(fileName,false);
519 }
520
521
522 /// <summary>
523 /// Upload a file and set the resume flag.
524 /// </summary>
525 /// <param name="fileName"></param>
526 /// <param name="resume"></param>
527 public void Upload(string fileName, bool resume)
528 {
529 if ( !this.loggedin ) this.Login();
530
531 Socket cSocket = null ;
532 long offset = 0;
533
534 if ( resume )
535 {
536 try
537 {
538 this.BinaryMode = true;
539
540 offset = GetFileSize( Path.GetFileName(fileName) );
541 }
542 catch(Exception)
543 {
544 // file not exist
545 offset = 0;
546 }
547 }
548
549 // open stream to read file
550 FileStream input = new FileStream(fileName,FileMode.Open);
551
552 if ( resume && input.Length < offset )
553 {
554 // different file size
555 Debug.WriteLine("Overwriting " + fileName, "FtpClient");
556 offset = 0;
557 }
558 else if ( resume && input.Length == offset )
559 {
560 // file done
561 input.Close();
562 Debug.WriteLine("Skipping completed " + fileName + " - turn resume off to not detect.", "FtpClient");
563 return;
564 }
565
566 // dont create untill we know that we need it
567 cSocket = this.createDataSocket();
568
569 if ( offset > 0 )
570 {
571 this.sendCommand( "REST " + offset );
572 if ( this.resultCode != 350 )
573 {
574 Debug.WriteLine("Resuming not supported", "FtpClient");
575 offset = 0;
576 }
577 }
578
579 this.sendCommand( "STOR " + Path.GetFileName(fileName) );
580
581 if ( this.resultCode != 125 && this.resultCode != 150 ) throw new FtpException(result.Substring(4));
582
583 if ( offset != 0 )
584 {
585 Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );
586
587 input.Seek(offset,SeekOrigin.Begin);
588 }
589
590 Debug.WriteLine( "Uploading file " + fileName + " to " + remotePath, "FtpClient" );
591
592 while ((bytes = input.Read(buffer,0,buffer.Length)) > 0)
593 {
594 cSocket.Send(buffer, bytes, 0);
595 }
596
597 input.Close();
598
599 if (cSocket.Connected)
600 {
601 cSocket.Close();
602 }
603
604 this.readResponse();
605
606 if( this.resultCode != 226 && this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
607 }
608
609 /// <summary>
610 /// Upload a directory and its file contents
611 /// </summary>
612 /// <param name="path"></param>
613 /// <param name="recurse">Whether to recurse sub directories</param>
614 public void UploadDirectory(string path, bool recurse)
615 {
616 this.UploadDirectory(path,recurse,"*.*");
617 }
618
619 /// <summary>
620 /// Upload a directory and its file contents
621 /// </summary>
622 /// <param name="path"></param>
623 /// <param name="recurse">Whether to recurse sub directories</param>
624 /// <param name="mask">Only upload files of the given mask - everything is '*.*'</param>
625 public void UploadDirectory(string path, bool recurse, string mask)
626 {
627 string[] dirs = path.Replace("/",@"\").Split('\\');
628 string rootDir = dirs[ dirs.Length - 1 ];
629
630 // make the root dir if it doed not exist
631 if ( this.GetFileList(rootDir).Length < 1 ) this.MakeDir(rootDir);
632
633 this.ChangeDir(rootDir);
634
635 foreach ( string file in Directory.GetFiles(path,mask) )
636 {
637 this.Upload(file,true);
638 }
639 if ( recurse )
640 {
641 foreach ( string directory in Directory.GetDirectories(path) )
642 {
643 this.UploadDirectory(directory,recurse,mask);
644 }
645 }
646
647 this.ChangeDir("..");
648 }
649
650 /// <summary>
651 /// Delete a file from the remote FTP server.
652 /// </summary>
653 /// <param name="fileName"></param>
654 public void DeleteFile(string fileName)
655 {
656 if ( !this.loggedin ) this.Login();
657
658 this.sendCommand( "DELE " + fileName );
659
660 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
661
662 Debug.WriteLine( "Deleted file " + fileName, "FtpClient" );
663 }
664
665 /// <summary>
666 /// Rename a file on the remote FTP server.
667 /// </summary>
668 /// <param name="oldFileName"></param>
669 /// <param name="newFileName"></param>
670 /// <param name="overwrite">setting to false will throw exception if it exists</param>
671 public void RenameFile(string oldFileName,string newFileName, bool overwrite)
672 {
673 if ( !this.loggedin ) this.Login();
674
675 this.sendCommand( "RNFR " + oldFileName );
676
677 if ( this.resultCode != 350 ) throw new FtpException(this.result.Substring(4));
678
679 if ( !overwrite && this.GetFileList(newFileName).Length > 0 ) throw new FtpException("File already exists");
680
681 this.sendCommand( "RNTO " + newFileName );
682
683 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
684
685 Debug.WriteLine( "Renamed file " + oldFileName + " to " + newFileName, "FtpClient" );
686 }
687
688 /// <summary>
689 /// Create a directory on the remote FTP server.
690 /// </summary>
691 /// <param name="dirName"></param>
692 public void MakeDir(string dirName)
693 {
694 if ( !this.loggedin ) this.Login();
695
696 this.sendCommand( "MKD " + dirName );
697
698 if ( this.resultCode != 250 && this.resultCode != 257 ) throw new FtpException(this.result.Substring(4));
699
700 Debug.WriteLine( "Created directory " + dirName, "FtpClient" );
701 }
702
703 /// <summary>
704 /// Delete a directory on the remote FTP server.
705 /// </summary>
706 /// <param name="dirName"></param>
707 public void RemoveDir(string dirName)
708 {
709 if ( !this.loggedin ) this.Login();
710
711 this.sendCommand( "RMD " + dirName );
712
713 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
714
715 Debug.WriteLine( "Removed directory " + dirName, "FtpClient" );
716 }
717
718 /// <summary>
719 /// Change the current working directory on the remote FTP server.
720 /// </summary>
721 /// <param name="dirName"></param>
722 public void ChangeDir(string dirName)
723 {
724 if( dirName == null || dirName.Equals(".") || dirName.Length == 0 )
725 {
726 return;
727 }
728
729 if ( !this.loggedin ) this.Login();
730
731 this.sendCommand( "CWD " + dirName );
732
733 if ( this.resultCode != 250 )
734 {
735 if (this.resultCode == 550)
736 throw new FtpException(String.Format("Access denied to {0}", this.remotePath + "/" + dirName));
737 throw new FtpException(result.Substring(4));
738 }
739
740 this.sendCommand( "PWD" );
741
742 if ( this.resultCode != 257 ) throw new FtpException(result.Substring(4));
743
744 // gonna have to do better than this....
745 this.remotePath = this.message.Split('"')[1];
746
747 Debug.WriteLine( "Current directory is " + this.remotePath, "FtpClient" );
748 }
749
750 /// <summary>
751 ///
752 /// </summary>
753 private void readResponse()
754 {
755 this.message = "";
756 this.result = this.readLine();
757
758 if ( this.result.Length > 3 )
759 this.resultCode = int.Parse( this.result.Substring(0,3) );
760 else
761 this.result = null;
762 }
763
764 /// <summary>
765 ///
766 /// </summary>
767 /// <returns></returns>
768 private string readLine()
769 {
770 while(true)
771 {
772 this.bytes = clientSocket.Receive( this.buffer, this.buffer.Length, 0 );
773 this.message += ASCII.GetString( this.buffer, 0, this.bytes );
774
775 if ( this.bytes < this.buffer.Length )
776 {
777 break;
778 }
779 }
780
781 string[] msg = this.message.Split('\n');
782
783 if ( this.message.Length > 2 )
784 this.message = msg[ msg.Length - 2 ];
785
786 else
787 this.message = msg[0];
788
789
790 if ( this.message.Length > 4 && !this.message.Substring(3,1).Equals(" ") ) return this.readLine();
791
792 if ( this.verboseDebugging )
793 {
794 for(int i = 0; i < msg.Length - 1; i++)
795 {
796 Debug.Write( msg[i], "FtpClient" );
797 }
798 }
799
800 return message;
801 }
802
803 /// <summary>
804 ///
805 /// </summary>
806 /// <param name="command"></param>
807 private void sendCommand(String command)
808 {
809 if ( this.verboseDebugging ) Debug.WriteLine(command,"FtpClient");
810
811 Byte[] cmdBytes = Encoding.ASCII.GetBytes( ( command + "\r\n" ).ToCharArray() );
812 clientSocket.Send( cmdBytes, cmdBytes.Length, 0);
813 this.readResponse();
814 }
815
816 /// <summary>
817 /// when doing data transfers, we need to open another socket for it.
818 /// </summary>
819 /// <returns>Connected socket</returns>
820 private Socket createDataSocket()
821 {
822 this.sendCommand("PASV");
823
824 if ( this.resultCode != 227 ) throw new FtpException(this.result.Substring(4));
825
826 int index1 = this.result.IndexOf('(');
827 int index2 = this.result.IndexOf(')');
828
829 string ipData = this.result.Substring(index1+1,index2-index1-1);
830
831 int[] parts = new int[6];
832
833 int len = ipData.Length;
834 int partCount = 0;
835 string buf="";
836
837 for (int i = 0; i < len && partCount <= 6; i++)
838 {
839 char ch = char.Parse( ipData.Substring(i,1) );
840
841 if ( char.IsDigit(ch) )
842 buf+=ch;
843
844 else if (ch != ',')
845 throw new FtpException("Malformed PASV result: " + result);
846
847 if ( ch == ',' || i+1 == len )
848 {
849 try
850 {
851 parts[partCount++] = int.Parse(buf);
852 buf = "";
853 }
854 catch (Exception ex)
855 {
856 throw new FtpException("Malformed PASV result (not supported?): " + this.result, ex);
857 }
858 }
859 }
860
861 string ipAddress = parts[0] + "."+ parts[1]+ "." + parts[2] + "." + parts[3];
862
863 int port = (parts[4] << 8) + parts[5];
864
865 Socket socket = null;
866 IPEndPoint ep = null;
867
868 try
869 {
870 socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
871 ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
872 socket.Connect(ep);
873 }
874 catch(Exception ex)
875 {
876 // doubtfull....
877 if ( socket != null && socket.Connected ) socket.Close();
878
879 throw new FtpException("Can't connect to remote server", ex);
880 }
881
882 return socket;
883 }
884
885 /// <summary>
886 /// Always release those sockets.
887 /// </summary>
888 private void cleanup()
889 {
890 if ( this.clientSocket!=null )
891 {
892 this.clientSocket.Close();
893 this.clientSocket = null;
894 }
895 this.loggedin = false;
896 }
897
898 /// <summary>
899 /// Destuctor
900 /// </summary>
901 ~FtpClient()
902 {
903 this.cleanup();
904 }
905
906
907 /**************************************************************************************************************/
908 #region Async methods (auto generated)
909
910 /*
911 WinInetApi.FtpClient ftp = new WinInetApi.FtpClient();
912
913 MethodInfo[] methods = ftp.GetType().GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public);
914
915 foreach ( MethodInfo method in methods )
916 {
917 string param = "";
918 string values = "";
919 foreach ( ParameterInfo i in method.GetParameters() )
920 {
921 param += i.ParameterType.Name + " " + i.Name + ",";
922 values += i.Name + ",";
923 }
924
925
926 Debug.WriteLine("private delegate " + method.ReturnType.Name + " " + method.Name + "Callback(" + param.TrimEnd(',') + ");");
927
928 Debug.WriteLine("public System.IAsyncResult Begin" + method.Name + "( " + param + " System.AsyncCallback callback )");
929 Debug.WriteLine("{");
930 Debug.WriteLine("" + method.Name + "Callback ftpCallback = new " + method.Name + "Callback(" + values + " this." + method.Name + ");");
931 Debug.WriteLine("return ftpCallback.BeginInvoke(callback, null);");
932 Debug.WriteLine("}");
933 Debug.WriteLine("public void End" + method.Name + "(System.IAsyncResult asyncResult)");
934 Debug.WriteLine("{");
935 Debug.WriteLine(method.Name + "Callback fc = (" + method.Name + "Callback) ((AsyncResult)asyncResult).AsyncDelegate;");
936 Debug.WriteLine("fc.EndInvoke(asyncResult);");
937 Debug.WriteLine("}");
938 //Debug.WriteLine(method);
939 }
940 */
941
942
943 private delegate void LoginCallback();
944 public System.IAsyncResult BeginLogin( System.AsyncCallback callback )
945 {
946 LoginCallback ftpCallback = new LoginCallback( this.Login);
947 return ftpCallback.BeginInvoke(callback, null);
948 }
949 private delegate void CloseCallback();
950 public System.IAsyncResult BeginClose( System.AsyncCallback callback )
951 {
952 CloseCallback ftpCallback = new CloseCallback( this.Close);
953 return ftpCallback.BeginInvoke(callback, null);
954 }
955 private delegate String[] GetFileListCallback();
956 public System.IAsyncResult BeginGetFileList( System.AsyncCallback callback )
957 {
958 GetFileListCallback ftpCallback = new GetFileListCallback( this.GetFileList);
959 return ftpCallback.BeginInvoke(callback, null);
960 }
961 private delegate String[] GetFileListMaskCallback(String mask);
962 public System.IAsyncResult BeginGetFileList( String mask, System.AsyncCallback callback )
963 {
964 GetFileListMaskCallback ftpCallback = new GetFileListMaskCallback(this.GetFileList);
965 return ftpCallback.BeginInvoke(mask, callback, null);
966 }
967 private delegate Int64 GetFileSizeCallback(String fileName);
968 public System.IAsyncResult BeginGetFileSize( String fileName, System.AsyncCallback callback )
969 {
970 GetFileSizeCallback ftpCallback = new GetFileSizeCallback(this.GetFileSize);
971 return ftpCallback.BeginInvoke(fileName, callback, null);
972 }
973 private delegate void DownloadCallback(String remFileName);
974 public System.IAsyncResult BeginDownload( String remFileName, System.AsyncCallback callback )
975 {
976 DownloadCallback ftpCallback = new DownloadCallback(this.Download);
977 return ftpCallback.BeginInvoke(remFileName, callback, null);
978 }
979 private delegate void DownloadFileNameResumeCallback(String remFileName,Boolean resume);
980 public System.IAsyncResult BeginDownload( String remFileName,Boolean resume, System.AsyncCallback callback )
981 {
982 DownloadFileNameResumeCallback ftpCallback = new DownloadFileNameResumeCallback(this.Download);
983 return ftpCallback.BeginInvoke(remFileName, resume, callback, null);
984 }
985 private delegate void DownloadFileNameFileNameCallback(String remFileName,String locFileName);
986 public System.IAsyncResult BeginDownload( String remFileName,String locFileName, System.AsyncCallback callback )
987 {
988 DownloadFileNameFileNameCallback ftpCallback = new DownloadFileNameFileNameCallback(this.Download);
989 return ftpCallback.BeginInvoke(remFileName, locFileName, callback, null);
990 }
991 private delegate void DownloadFileNameFileNameResumeCallback(String remFileName,String locFileName,Boolean resume);
992 public System.IAsyncResult BeginDownload( String remFileName,String locFileName,Boolean resume, System.AsyncCallback callback )
993 {
994 DownloadFileNameFileNameResumeCallback ftpCallback = new DownloadFileNameFileNameResumeCallback(this.Download);
995 return ftpCallback.BeginInvoke(remFileName, locFileName, resume, callback, null);
996 }
997 private delegate void UploadCallback(String fileName);
998 public System.IAsyncResult BeginUpload( String fileName, System.AsyncCallback callback )
999 {
1000 UploadCallback ftpCallback = new UploadCallback(this.Upload);
1001 return ftpCallback.BeginInvoke(fileName, callback, null);
1002 }
1003 private delegate void UploadFileNameResumeCallback(String fileName,Boolean resume);
1004 public System.IAsyncResult BeginUpload( String fileName,Boolean resume, System.AsyncCallback callback )
1005 {
1006 UploadFileNameResumeCallback ftpCallback = new UploadFileNameResumeCallback(this.Upload);
1007 return ftpCallback.BeginInvoke(fileName, resume, callback, null);
1008 }
1009 private delegate void UploadDirectoryCallback(String path,Boolean recurse);
1010 public System.IAsyncResult BeginUploadDirectory( String path,Boolean recurse, System.AsyncCallback callback )
1011 {
1012 UploadDirectoryCallback ftpCallback = new UploadDirectoryCallback(this.UploadDirectory);
1013 return ftpCallback.BeginInvoke(path, recurse, callback, null);
1014 }
1015 private delegate void UploadDirectoryPathRecurseMaskCallback(String path,Boolean recurse,String mask);
1016 public System.IAsyncResult BeginUploadDirectory( String path,Boolean recurse,String mask, System.AsyncCallback callback )
1017 {
1018 UploadDirectoryPathRecurseMaskCallback ftpCallback = new UploadDirectoryPathRecurseMaskCallback(this.UploadDirectory);
1019 return ftpCallback.BeginInvoke(path, recurse, mask, callback, null);
1020 }
1021 private delegate void DeleteFileCallback(String fileName);
1022 public System.IAsyncResult BeginDeleteFile( String fileName, System.AsyncCallback callback )
1023 {
1024 DeleteFileCallback ftpCallback = new DeleteFileCallback(this.DeleteFile);
1025 return ftpCallback.BeginInvoke(fileName, callback, null);
1026 }
1027 private delegate void RenameFileCallback(String oldFileName,String newFileName,Boolean overwrite);
1028 public System.IAsyncResult BeginRenameFile( String oldFileName,String newFileName,Boolean overwrite, System.AsyncCallback callback )
1029 {
1030 RenameFileCallback ftpCallback = new RenameFileCallback(this.RenameFile);
1031 return ftpCallback.BeginInvoke(oldFileName, newFileName, overwrite, callback, null);
1032 }
1033 private delegate void MakeDirCallback(String dirName);
1034 public System.IAsyncResult BeginMakeDir( String dirName, System.AsyncCallback callback )
1035 {
1036 MakeDirCallback ftpCallback = new MakeDirCallback(this.MakeDir);
1037 return ftpCallback.BeginInvoke(dirName, callback, null);
1038 }
1039 private delegate void RemoveDirCallback(String dirName);
1040 public System.IAsyncResult BeginRemoveDir( String dirName, System.AsyncCallback callback )
1041 {
1042 RemoveDirCallback ftpCallback = new RemoveDirCallback(this.RemoveDir);
1043 return ftpCallback.BeginInvoke(dirName, callback, null);
1044 }
1045 private delegate void ChangeDirCallback(String dirName);
1046 public System.IAsyncResult BeginChangeDir( String dirName, System.AsyncCallback callback )
1047 {
1048 ChangeDirCallback ftpCallback = new ChangeDirCallback(this.ChangeDir);
1049 return ftpCallback.BeginInvoke(dirName, callback, null);
1050 }
1051
1052 #endregion
1053 }
1054 }