Publish ISOs via FTP
[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 /// <summary>
359 /// Return the size of a file.
360 /// </summary>
361 /// <param name="fileName"></param>
362 /// <returns></returns>
363 public long GetFileSize(string fileName)
364 {
365 if ( !this.loggedin ) this.Login();
366
367 this.sendCommand("SIZE " + fileName);
368 long size=0;
369
370 if ( this.resultCode == 213 )
371 size = long.Parse(this.result.Substring(4));
372
373 else
374 throw new FtpException(this.result.Substring(4));
375
376 return size;
377 }
378
379
380 /// <summary>
381 /// Download a file to the Assembly's local directory,
382 /// keeping the same file name.
383 /// </summary>
384 /// <param name="remFileName"></param>
385 public void Download(string remFileName)
386 {
387 this.Download(remFileName,"",false);
388 }
389
390 /// <summary>
391 /// Download a remote file to the Assembly's local directory,
392 /// keeping the same file name, and set the resume flag.
393 /// </summary>
394 /// <param name="remFileName"></param>
395 /// <param name="resume"></param>
396 public void Download(string remFileName,Boolean resume)
397 {
398 this.Download(remFileName,"",resume);
399 }
400
401 /// <summary>
402 /// Download a remote file to a local file name which can include
403 /// a path. The local file name will be created or overwritten,
404 /// but the path must exist.
405 /// </summary>
406 /// <param name="remFileName"></param>
407 /// <param name="locFileName"></param>
408 public void Download(string remFileName,string locFileName)
409 {
410 this.Download(remFileName,locFileName,false);
411 }
412
413 /// <summary>
414 /// Download a remote file to a local file name which can include
415 /// a path, and set the resume flag. The local file name will be
416 /// created or overwritten, but the path must exist.
417 /// </summary>
418 /// <param name="remFileName"></param>
419 /// <param name="locFileName"></param>
420 /// <param name="resume"></param>
421 public void Download(string remFileName,string locFileName,Boolean resume)
422 {
423 if ( !this.loggedin ) this.Login();
424
425 this.BinaryMode = true;
426
427 Debug.WriteLine("Downloading file " + remFileName + " from " + server + "/" + remotePath, "FtpClient" );
428
429 if (locFileName.Equals(""))
430 {
431 locFileName = remFileName;
432 }
433
434 FileStream output = null;
435
436 if ( !File.Exists(locFileName) )
437 output = File.Create(locFileName);
438
439 else
440 output = new FileStream(locFileName,FileMode.Open);
441
442 Socket cSocket = createDataSocket();
443
444 long offset = 0;
445
446 if ( resume )
447 {
448 offset = output.Length;
449
450 if ( offset > 0 )
451 {
452 this.sendCommand( "REST " + offset );
453 if ( this.resultCode != 350 )
454 {
455 //Server dosnt support resuming
456 offset = 0;
457 Debug.WriteLine("Resuming not supported:" + result.Substring(4), "FtpClient" );
458 }
459 else
460 {
461 Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );
462 output.Seek( offset, SeekOrigin.Begin );
463 }
464 }
465 }
466
467 this.sendCommand("RETR " + remFileName);
468
469 if ( this.resultCode != 150 && this.resultCode != 125 )
470 {
471 throw new FtpException(this.result.Substring(4));
472 }
473
474 DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);
475
476 while ( timeout > DateTime.Now )
477 {
478 this.bytes = cSocket.Receive(buffer, buffer.Length, 0);
479 output.Write(this.buffer,0,this.bytes);
480
481 if ( this.bytes <= 0)
482 {
483 break;
484 }
485 }
486
487 output.Close();
488
489 if ( cSocket.Connected ) cSocket.Close();
490
491 this.readResponse();
492
493 if( this.resultCode != 226 && this.resultCode != 250 )
494 throw new FtpException(this.result.Substring(4));
495 }
496
497
498 /// <summary>
499 /// Upload a file.
500 /// </summary>
501 /// <param name="fileName"></param>
502 public void Upload(string fileName)
503 {
504 this.Upload(fileName,false);
505 }
506
507
508 /// <summary>
509 /// Upload a file and set the resume flag.
510 /// </summary>
511 /// <param name="fileName"></param>
512 /// <param name="resume"></param>
513 public void Upload(string fileName, bool resume)
514 {
515 if ( !this.loggedin ) this.Login();
516
517 Socket cSocket = null ;
518 long offset = 0;
519
520 if ( resume )
521 {
522 try
523 {
524 this.BinaryMode = true;
525
526 offset = GetFileSize( Path.GetFileName(fileName) );
527 }
528 catch(Exception)
529 {
530 // file not exist
531 offset = 0;
532 }
533 }
534
535 // open stream to read file
536 FileStream input = new FileStream(fileName,FileMode.Open);
537
538 if ( resume && input.Length < offset )
539 {
540 // different file size
541 Debug.WriteLine("Overwriting " + fileName, "FtpClient");
542 offset = 0;
543 }
544 else if ( resume && input.Length == offset )
545 {
546 // file done
547 input.Close();
548 Debug.WriteLine("Skipping completed " + fileName + " - turn resume off to not detect.", "FtpClient");
549 return;
550 }
551
552 // dont create untill we know that we need it
553 cSocket = this.createDataSocket();
554
555 if ( offset > 0 )
556 {
557 this.sendCommand( "REST " + offset );
558 if ( this.resultCode != 350 )
559 {
560 Debug.WriteLine("Resuming not supported", "FtpClient");
561 offset = 0;
562 }
563 }
564
565 this.sendCommand( "STOR " + Path.GetFileName(fileName) );
566
567 if ( this.resultCode != 125 && this.resultCode != 150 ) throw new FtpException(result.Substring(4));
568
569 if ( offset != 0 )
570 {
571 Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );
572
573 input.Seek(offset,SeekOrigin.Begin);
574 }
575
576 Debug.WriteLine( "Uploading file " + fileName + " to " + remotePath, "FtpClient" );
577
578 while ((bytes = input.Read(buffer,0,buffer.Length)) > 0)
579 {
580 cSocket.Send(buffer, bytes, 0);
581 }
582
583 input.Close();
584
585 if (cSocket.Connected)
586 {
587 cSocket.Close();
588 }
589
590 this.readResponse();
591
592 if( this.resultCode != 226 && this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
593 }
594
595 /// <summary>
596 /// Upload a directory and its file contents
597 /// </summary>
598 /// <param name="path"></param>
599 /// <param name="recurse">Whether to recurse sub directories</param>
600 public void UploadDirectory(string path, bool recurse)
601 {
602 this.UploadDirectory(path,recurse,"*.*");
603 }
604
605 /// <summary>
606 /// Upload a directory and its file contents
607 /// </summary>
608 /// <param name="path"></param>
609 /// <param name="recurse">Whether to recurse sub directories</param>
610 /// <param name="mask">Only upload files of the given mask - everything is '*.*'</param>
611 public void UploadDirectory(string path, bool recurse, string mask)
612 {
613 string[] dirs = path.Replace("/",@"\").Split('\\');
614 string rootDir = dirs[ dirs.Length - 1 ];
615
616 // make the root dir if it doed not exist
617 if ( this.GetFileList(rootDir).Length < 1 ) this.MakeDir(rootDir);
618
619 this.ChangeDir(rootDir);
620
621 foreach ( string file in Directory.GetFiles(path,mask) )
622 {
623 this.Upload(file,true);
624 }
625 if ( recurse )
626 {
627 foreach ( string directory in Directory.GetDirectories(path) )
628 {
629 this.UploadDirectory(directory,recurse,mask);
630 }
631 }
632
633 this.ChangeDir("..");
634 }
635
636 /// <summary>
637 /// Delete a file from the remote FTP server.
638 /// </summary>
639 /// <param name="fileName"></param>
640 public void DeleteFile(string fileName)
641 {
642 if ( !this.loggedin ) this.Login();
643
644 this.sendCommand( "DELE " + fileName );
645
646 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
647
648 Debug.WriteLine( "Deleted file " + fileName, "FtpClient" );
649 }
650
651 /// <summary>
652 /// Rename a file on the remote FTP server.
653 /// </summary>
654 /// <param name="oldFileName"></param>
655 /// <param name="newFileName"></param>
656 /// <param name="overwrite">setting to false will throw exception if it exists</param>
657 public void RenameFile(string oldFileName,string newFileName, bool overwrite)
658 {
659 if ( !this.loggedin ) this.Login();
660
661 this.sendCommand( "RNFR " + oldFileName );
662
663 if ( this.resultCode != 350 ) throw new FtpException(this.result.Substring(4));
664
665 if ( !overwrite && this.GetFileList(newFileName).Length > 0 ) throw new FtpException("File already exists");
666
667 this.sendCommand( "RNTO " + newFileName );
668
669 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
670
671 Debug.WriteLine( "Renamed file " + oldFileName + " to " + newFileName, "FtpClient" );
672 }
673
674 /// <summary>
675 /// Create a directory on the remote FTP server.
676 /// </summary>
677 /// <param name="dirName"></param>
678 public void MakeDir(string dirName)
679 {
680 if ( !this.loggedin ) this.Login();
681
682 this.sendCommand( "MKD " + dirName );
683
684 if ( this.resultCode != 250 && this.resultCode != 257 ) throw new FtpException(this.result.Substring(4));
685
686 Debug.WriteLine( "Created directory " + dirName, "FtpClient" );
687 }
688
689 /// <summary>
690 /// Delete a directory on the remote FTP server.
691 /// </summary>
692 /// <param name="dirName"></param>
693 public void RemoveDir(string dirName)
694 {
695 if ( !this.loggedin ) this.Login();
696
697 this.sendCommand( "RMD " + dirName );
698
699 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
700
701 Debug.WriteLine( "Removed directory " + dirName, "FtpClient" );
702 }
703
704 /// <summary>
705 /// Change the current working directory on the remote FTP server.
706 /// </summary>
707 /// <param name="dirName"></param>
708 public void ChangeDir(string dirName)
709 {
710 if( dirName == null || dirName.Equals(".") || dirName.Length == 0 )
711 {
712 return;
713 }
714
715 if ( !this.loggedin ) this.Login();
716
717 this.sendCommand( "CWD " + dirName );
718
719 if ( this.resultCode != 250 ) throw new FtpException(result.Substring(4));
720
721 this.sendCommand( "PWD" );
722
723 if ( this.resultCode != 257 ) throw new FtpException(result.Substring(4));
724
725 // gonna have to do better than this....
726 this.remotePath = this.message.Split('"')[1];
727
728 Debug.WriteLine( "Current directory is " + this.remotePath, "FtpClient" );
729 }
730
731 /// <summary>
732 ///
733 /// </summary>
734 private void readResponse()
735 {
736 this.message = "";
737 this.result = this.readLine();
738
739 if ( this.result.Length > 3 )
740 this.resultCode = int.Parse( this.result.Substring(0,3) );
741 else
742 this.result = null;
743 }
744
745 /// <summary>
746 ///
747 /// </summary>
748 /// <returns></returns>
749 private string readLine()
750 {
751 while(true)
752 {
753 this.bytes = clientSocket.Receive( this.buffer, this.buffer.Length, 0 );
754 this.message += ASCII.GetString( this.buffer, 0, this.bytes );
755
756 if ( this.bytes < this.buffer.Length )
757 {
758 break;
759 }
760 }
761
762 string[] msg = this.message.Split('\n');
763
764 if ( this.message.Length > 2 )
765 this.message = msg[ msg.Length - 2 ];
766
767 else
768 this.message = msg[0];
769
770
771 if ( this.message.Length > 4 && !this.message.Substring(3,1).Equals(" ") ) return this.readLine();
772
773 if ( this.verboseDebugging )
774 {
775 for(int i = 0; i < msg.Length - 1; i++)
776 {
777 Debug.Write( msg[i], "FtpClient" );
778 }
779 }
780
781 return message;
782 }
783
784 /// <summary>
785 ///
786 /// </summary>
787 /// <param name="command"></param>
788 private void sendCommand(String command)
789 {
790 if ( this.verboseDebugging ) Debug.WriteLine(command,"FtpClient");
791
792 Byte[] cmdBytes = Encoding.ASCII.GetBytes( ( command + "\r\n" ).ToCharArray() );
793 clientSocket.Send( cmdBytes, cmdBytes.Length, 0);
794 this.readResponse();
795 }
796
797 /// <summary>
798 /// when doing data transfers, we need to open another socket for it.
799 /// </summary>
800 /// <returns>Connected socket</returns>
801 private Socket createDataSocket()
802 {
803 this.sendCommand("PASV");
804
805 if ( this.resultCode != 227 ) throw new FtpException(this.result.Substring(4));
806
807 int index1 = this.result.IndexOf('(');
808 int index2 = this.result.IndexOf(')');
809
810 string ipData = this.result.Substring(index1+1,index2-index1-1);
811
812 int[] parts = new int[6];
813
814 int len = ipData.Length;
815 int partCount = 0;
816 string buf="";
817
818 for (int i = 0; i < len && partCount <= 6; i++)
819 {
820 char ch = char.Parse( ipData.Substring(i,1) );
821
822 if ( char.IsDigit(ch) )
823 buf+=ch;
824
825 else if (ch != ',')
826 throw new FtpException("Malformed PASV result: " + result);
827
828 if ( ch == ',' || i+1 == len )
829 {
830 try
831 {
832 parts[partCount++] = int.Parse(buf);
833 buf = "";
834 }
835 catch (Exception ex)
836 {
837 throw new FtpException("Malformed PASV result (not supported?): " + this.result, ex);
838 }
839 }
840 }
841
842 string ipAddress = parts[0] + "."+ parts[1]+ "." + parts[2] + "." + parts[3];
843
844 int port = (parts[4] << 8) + parts[5];
845
846 Socket socket = null;
847 IPEndPoint ep = null;
848
849 try
850 {
851 socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
852 ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
853 socket.Connect(ep);
854 }
855 catch(Exception ex)
856 {
857 // doubtfull....
858 if ( socket != null && socket.Connected ) socket.Close();
859
860 throw new FtpException("Can't connect to remote server", ex);
861 }
862
863 return socket;
864 }
865
866 /// <summary>
867 /// Always release those sockets.
868 /// </summary>
869 private void cleanup()
870 {
871 if ( this.clientSocket!=null )
872 {
873 this.clientSocket.Close();
874 this.clientSocket = null;
875 }
876 this.loggedin = false;
877 }
878
879 /// <summary>
880 /// Destuctor
881 /// </summary>
882 ~FtpClient()
883 {
884 this.cleanup();
885 }
886
887
888 /**************************************************************************************************************/
889 #region Async methods (auto generated)
890
891 /*
892 WinInetApi.FtpClient ftp = new WinInetApi.FtpClient();
893
894 MethodInfo[] methods = ftp.GetType().GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public);
895
896 foreach ( MethodInfo method in methods )
897 {
898 string param = "";
899 string values = "";
900 foreach ( ParameterInfo i in method.GetParameters() )
901 {
902 param += i.ParameterType.Name + " " + i.Name + ",";
903 values += i.Name + ",";
904 }
905
906
907 Debug.WriteLine("private delegate " + method.ReturnType.Name + " " + method.Name + "Callback(" + param.TrimEnd(',') + ");");
908
909 Debug.WriteLine("public System.IAsyncResult Begin" + method.Name + "( " + param + " System.AsyncCallback callback )");
910 Debug.WriteLine("{");
911 Debug.WriteLine("" + method.Name + "Callback ftpCallback = new " + method.Name + "Callback(" + values + " this." + method.Name + ");");
912 Debug.WriteLine("return ftpCallback.BeginInvoke(callback, null);");
913 Debug.WriteLine("}");
914 Debug.WriteLine("public void End" + method.Name + "(System.IAsyncResult asyncResult)");
915 Debug.WriteLine("{");
916 Debug.WriteLine(method.Name + "Callback fc = (" + method.Name + "Callback) ((AsyncResult)asyncResult).AsyncDelegate;");
917 Debug.WriteLine("fc.EndInvoke(asyncResult);");
918 Debug.WriteLine("}");
919 //Debug.WriteLine(method);
920 }
921 */
922
923
924 private delegate void LoginCallback();
925 public System.IAsyncResult BeginLogin( System.AsyncCallback callback )
926 {
927 LoginCallback ftpCallback = new LoginCallback( this.Login);
928 return ftpCallback.BeginInvoke(callback, null);
929 }
930 private delegate void CloseCallback();
931 public System.IAsyncResult BeginClose( System.AsyncCallback callback )
932 {
933 CloseCallback ftpCallback = new CloseCallback( this.Close);
934 return ftpCallback.BeginInvoke(callback, null);
935 }
936 private delegate String[] GetFileListCallback();
937 public System.IAsyncResult BeginGetFileList( System.AsyncCallback callback )
938 {
939 GetFileListCallback ftpCallback = new GetFileListCallback( this.GetFileList);
940 return ftpCallback.BeginInvoke(callback, null);
941 }
942 private delegate String[] GetFileListMaskCallback(String mask);
943 public System.IAsyncResult BeginGetFileList( String mask, System.AsyncCallback callback )
944 {
945 GetFileListMaskCallback ftpCallback = new GetFileListMaskCallback(this.GetFileList);
946 return ftpCallback.BeginInvoke(mask, callback, null);
947 }
948 private delegate Int64 GetFileSizeCallback(String fileName);
949 public System.IAsyncResult BeginGetFileSize( String fileName, System.AsyncCallback callback )
950 {
951 GetFileSizeCallback ftpCallback = new GetFileSizeCallback(this.GetFileSize);
952 return ftpCallback.BeginInvoke(fileName, callback, null);
953 }
954 private delegate void DownloadCallback(String remFileName);
955 public System.IAsyncResult BeginDownload( String remFileName, System.AsyncCallback callback )
956 {
957 DownloadCallback ftpCallback = new DownloadCallback(this.Download);
958 return ftpCallback.BeginInvoke(remFileName, callback, null);
959 }
960 private delegate void DownloadFileNameResumeCallback(String remFileName,Boolean resume);
961 public System.IAsyncResult BeginDownload( String remFileName,Boolean resume, System.AsyncCallback callback )
962 {
963 DownloadFileNameResumeCallback ftpCallback = new DownloadFileNameResumeCallback(this.Download);
964 return ftpCallback.BeginInvoke(remFileName, resume, callback, null);
965 }
966 private delegate void DownloadFileNameFileNameCallback(String remFileName,String locFileName);
967 public System.IAsyncResult BeginDownload( String remFileName,String locFileName, System.AsyncCallback callback )
968 {
969 DownloadFileNameFileNameCallback ftpCallback = new DownloadFileNameFileNameCallback(this.Download);
970 return ftpCallback.BeginInvoke(remFileName, locFileName, callback, null);
971 }
972 private delegate void DownloadFileNameFileNameResumeCallback(String remFileName,String locFileName,Boolean resume);
973 public System.IAsyncResult BeginDownload( String remFileName,String locFileName,Boolean resume, System.AsyncCallback callback )
974 {
975 DownloadFileNameFileNameResumeCallback ftpCallback = new DownloadFileNameFileNameResumeCallback(this.Download);
976 return ftpCallback.BeginInvoke(remFileName, locFileName, resume, callback, null);
977 }
978 private delegate void UploadCallback(String fileName);
979 public System.IAsyncResult BeginUpload( String fileName, System.AsyncCallback callback )
980 {
981 UploadCallback ftpCallback = new UploadCallback(this.Upload);
982 return ftpCallback.BeginInvoke(fileName, callback, null);
983 }
984 private delegate void UploadFileNameResumeCallback(String fileName,Boolean resume);
985 public System.IAsyncResult BeginUpload( String fileName,Boolean resume, System.AsyncCallback callback )
986 {
987 UploadFileNameResumeCallback ftpCallback = new UploadFileNameResumeCallback(this.Upload);
988 return ftpCallback.BeginInvoke(fileName, resume, callback, null);
989 }
990 private delegate void UploadDirectoryCallback(String path,Boolean recurse);
991 public System.IAsyncResult BeginUploadDirectory( String path,Boolean recurse, System.AsyncCallback callback )
992 {
993 UploadDirectoryCallback ftpCallback = new UploadDirectoryCallback(this.UploadDirectory);
994 return ftpCallback.BeginInvoke(path, recurse, callback, null);
995 }
996 private delegate void UploadDirectoryPathRecurseMaskCallback(String path,Boolean recurse,String mask);
997 public System.IAsyncResult BeginUploadDirectory( String path,Boolean recurse,String mask, System.AsyncCallback callback )
998 {
999 UploadDirectoryPathRecurseMaskCallback ftpCallback = new UploadDirectoryPathRecurseMaskCallback(this.UploadDirectory);
1000 return ftpCallback.BeginInvoke(path, recurse, mask, callback, null);
1001 }
1002 private delegate void DeleteFileCallback(String fileName);
1003 public System.IAsyncResult BeginDeleteFile( String fileName, System.AsyncCallback callback )
1004 {
1005 DeleteFileCallback ftpCallback = new DeleteFileCallback(this.DeleteFile);
1006 return ftpCallback.BeginInvoke(fileName, callback, null);
1007 }
1008 private delegate void RenameFileCallback(String oldFileName,String newFileName,Boolean overwrite);
1009 public System.IAsyncResult BeginRenameFile( String oldFileName,String newFileName,Boolean overwrite, System.AsyncCallback callback )
1010 {
1011 RenameFileCallback ftpCallback = new RenameFileCallback(this.RenameFile);
1012 return ftpCallback.BeginInvoke(oldFileName, newFileName, overwrite, callback, null);
1013 }
1014 private delegate void MakeDirCallback(String dirName);
1015 public System.IAsyncResult BeginMakeDir( String dirName, System.AsyncCallback callback )
1016 {
1017 MakeDirCallback ftpCallback = new MakeDirCallback(this.MakeDir);
1018 return ftpCallback.BeginInvoke(dirName, callback, null);
1019 }
1020 private delegate void RemoveDirCallback(String dirName);
1021 public System.IAsyncResult BeginRemoveDir( String dirName, System.AsyncCallback callback )
1022 {
1023 RemoveDirCallback ftpCallback = new RemoveDirCallback(this.RemoveDir);
1024 return ftpCallback.BeginInvoke(dirName, callback, null);
1025 }
1026 private delegate void ChangeDirCallback(String dirName);
1027 public System.IAsyncResult BeginChangeDir( String dirName, System.AsyncCallback callback )
1028 {
1029 ChangeDirCallback ftpCallback = new ChangeDirCallback(this.ChangeDir);
1030 return ftpCallback.BeginInvoke(dirName, callback, null);
1031 }
1032
1033 #endregion
1034 }
1035 }