Check for presence of directory
[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 ) throw new FtpException(result.Substring(4));
734
735 this.sendCommand( "PWD" );
736
737 if ( this.resultCode != 257 ) throw new FtpException(result.Substring(4));
738
739 // gonna have to do better than this....
740 this.remotePath = this.message.Split('"')[1];
741
742 Debug.WriteLine( "Current directory is " + this.remotePath, "FtpClient" );
743 }
744
745 /// <summary>
746 ///
747 /// </summary>
748 private void readResponse()
749 {
750 this.message = "";
751 this.result = this.readLine();
752
753 if ( this.result.Length > 3 )
754 this.resultCode = int.Parse( this.result.Substring(0,3) );
755 else
756 this.result = null;
757 }
758
759 /// <summary>
760 ///
761 /// </summary>
762 /// <returns></returns>
763 private string readLine()
764 {
765 while(true)
766 {
767 this.bytes = clientSocket.Receive( this.buffer, this.buffer.Length, 0 );
768 this.message += ASCII.GetString( this.buffer, 0, this.bytes );
769
770 if ( this.bytes < this.buffer.Length )
771 {
772 break;
773 }
774 }
775
776 string[] msg = this.message.Split('\n');
777
778 if ( this.message.Length > 2 )
779 this.message = msg[ msg.Length - 2 ];
780
781 else
782 this.message = msg[0];
783
784
785 if ( this.message.Length > 4 && !this.message.Substring(3,1).Equals(" ") ) return this.readLine();
786
787 if ( this.verboseDebugging )
788 {
789 for(int i = 0; i < msg.Length - 1; i++)
790 {
791 Debug.Write( msg[i], "FtpClient" );
792 }
793 }
794
795 return message;
796 }
797
798 /// <summary>
799 ///
800 /// </summary>
801 /// <param name="command"></param>
802 private void sendCommand(String command)
803 {
804 if ( this.verboseDebugging ) Debug.WriteLine(command,"FtpClient");
805
806 Byte[] cmdBytes = Encoding.ASCII.GetBytes( ( command + "\r\n" ).ToCharArray() );
807 clientSocket.Send( cmdBytes, cmdBytes.Length, 0);
808 this.readResponse();
809 }
810
811 /// <summary>
812 /// when doing data transfers, we need to open another socket for it.
813 /// </summary>
814 /// <returns>Connected socket</returns>
815 private Socket createDataSocket()
816 {
817 this.sendCommand("PASV");
818
819 if ( this.resultCode != 227 ) throw new FtpException(this.result.Substring(4));
820
821 int index1 = this.result.IndexOf('(');
822 int index2 = this.result.IndexOf(')');
823
824 string ipData = this.result.Substring(index1+1,index2-index1-1);
825
826 int[] parts = new int[6];
827
828 int len = ipData.Length;
829 int partCount = 0;
830 string buf="";
831
832 for (int i = 0; i < len && partCount <= 6; i++)
833 {
834 char ch = char.Parse( ipData.Substring(i,1) );
835
836 if ( char.IsDigit(ch) )
837 buf+=ch;
838
839 else if (ch != ',')
840 throw new FtpException("Malformed PASV result: " + result);
841
842 if ( ch == ',' || i+1 == len )
843 {
844 try
845 {
846 parts[partCount++] = int.Parse(buf);
847 buf = "";
848 }
849 catch (Exception ex)
850 {
851 throw new FtpException("Malformed PASV result (not supported?): " + this.result, ex);
852 }
853 }
854 }
855
856 string ipAddress = parts[0] + "."+ parts[1]+ "." + parts[2] + "." + parts[3];
857
858 int port = (parts[4] << 8) + parts[5];
859
860 Socket socket = null;
861 IPEndPoint ep = null;
862
863 try
864 {
865 socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
866 ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
867 socket.Connect(ep);
868 }
869 catch(Exception ex)
870 {
871 // doubtfull....
872 if ( socket != null && socket.Connected ) socket.Close();
873
874 throw new FtpException("Can't connect to remote server", ex);
875 }
876
877 return socket;
878 }
879
880 /// <summary>
881 /// Always release those sockets.
882 /// </summary>
883 private void cleanup()
884 {
885 if ( this.clientSocket!=null )
886 {
887 this.clientSocket.Close();
888 this.clientSocket = null;
889 }
890 this.loggedin = false;
891 }
892
893 /// <summary>
894 /// Destuctor
895 /// </summary>
896 ~FtpClient()
897 {
898 this.cleanup();
899 }
900
901
902 /**************************************************************************************************************/
903 #region Async methods (auto generated)
904
905 /*
906 WinInetApi.FtpClient ftp = new WinInetApi.FtpClient();
907
908 MethodInfo[] methods = ftp.GetType().GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public);
909
910 foreach ( MethodInfo method in methods )
911 {
912 string param = "";
913 string values = "";
914 foreach ( ParameterInfo i in method.GetParameters() )
915 {
916 param += i.ParameterType.Name + " " + i.Name + ",";
917 values += i.Name + ",";
918 }
919
920
921 Debug.WriteLine("private delegate " + method.ReturnType.Name + " " + method.Name + "Callback(" + param.TrimEnd(',') + ");");
922
923 Debug.WriteLine("public System.IAsyncResult Begin" + method.Name + "( " + param + " System.AsyncCallback callback )");
924 Debug.WriteLine("{");
925 Debug.WriteLine("" + method.Name + "Callback ftpCallback = new " + method.Name + "Callback(" + values + " this." + method.Name + ");");
926 Debug.WriteLine("return ftpCallback.BeginInvoke(callback, null);");
927 Debug.WriteLine("}");
928 Debug.WriteLine("public void End" + method.Name + "(System.IAsyncResult asyncResult)");
929 Debug.WriteLine("{");
930 Debug.WriteLine(method.Name + "Callback fc = (" + method.Name + "Callback) ((AsyncResult)asyncResult).AsyncDelegate;");
931 Debug.WriteLine("fc.EndInvoke(asyncResult);");
932 Debug.WriteLine("}");
933 //Debug.WriteLine(method);
934 }
935 */
936
937
938 private delegate void LoginCallback();
939 public System.IAsyncResult BeginLogin( System.AsyncCallback callback )
940 {
941 LoginCallback ftpCallback = new LoginCallback( this.Login);
942 return ftpCallback.BeginInvoke(callback, null);
943 }
944 private delegate void CloseCallback();
945 public System.IAsyncResult BeginClose( System.AsyncCallback callback )
946 {
947 CloseCallback ftpCallback = new CloseCallback( this.Close);
948 return ftpCallback.BeginInvoke(callback, null);
949 }
950 private delegate String[] GetFileListCallback();
951 public System.IAsyncResult BeginGetFileList( System.AsyncCallback callback )
952 {
953 GetFileListCallback ftpCallback = new GetFileListCallback( this.GetFileList);
954 return ftpCallback.BeginInvoke(callback, null);
955 }
956 private delegate String[] GetFileListMaskCallback(String mask);
957 public System.IAsyncResult BeginGetFileList( String mask, System.AsyncCallback callback )
958 {
959 GetFileListMaskCallback ftpCallback = new GetFileListMaskCallback(this.GetFileList);
960 return ftpCallback.BeginInvoke(mask, callback, null);
961 }
962 private delegate Int64 GetFileSizeCallback(String fileName);
963 public System.IAsyncResult BeginGetFileSize( String fileName, System.AsyncCallback callback )
964 {
965 GetFileSizeCallback ftpCallback = new GetFileSizeCallback(this.GetFileSize);
966 return ftpCallback.BeginInvoke(fileName, callback, null);
967 }
968 private delegate void DownloadCallback(String remFileName);
969 public System.IAsyncResult BeginDownload( String remFileName, System.AsyncCallback callback )
970 {
971 DownloadCallback ftpCallback = new DownloadCallback(this.Download);
972 return ftpCallback.BeginInvoke(remFileName, callback, null);
973 }
974 private delegate void DownloadFileNameResumeCallback(String remFileName,Boolean resume);
975 public System.IAsyncResult BeginDownload( String remFileName,Boolean resume, System.AsyncCallback callback )
976 {
977 DownloadFileNameResumeCallback ftpCallback = new DownloadFileNameResumeCallback(this.Download);
978 return ftpCallback.BeginInvoke(remFileName, resume, callback, null);
979 }
980 private delegate void DownloadFileNameFileNameCallback(String remFileName,String locFileName);
981 public System.IAsyncResult BeginDownload( String remFileName,String locFileName, System.AsyncCallback callback )
982 {
983 DownloadFileNameFileNameCallback ftpCallback = new DownloadFileNameFileNameCallback(this.Download);
984 return ftpCallback.BeginInvoke(remFileName, locFileName, callback, null);
985 }
986 private delegate void DownloadFileNameFileNameResumeCallback(String remFileName,String locFileName,Boolean resume);
987 public System.IAsyncResult BeginDownload( String remFileName,String locFileName,Boolean resume, System.AsyncCallback callback )
988 {
989 DownloadFileNameFileNameResumeCallback ftpCallback = new DownloadFileNameFileNameResumeCallback(this.Download);
990 return ftpCallback.BeginInvoke(remFileName, locFileName, resume, callback, null);
991 }
992 private delegate void UploadCallback(String fileName);
993 public System.IAsyncResult BeginUpload( String fileName, System.AsyncCallback callback )
994 {
995 UploadCallback ftpCallback = new UploadCallback(this.Upload);
996 return ftpCallback.BeginInvoke(fileName, callback, null);
997 }
998 private delegate void UploadFileNameResumeCallback(String fileName,Boolean resume);
999 public System.IAsyncResult BeginUpload( String fileName,Boolean resume, System.AsyncCallback callback )
1000 {
1001 UploadFileNameResumeCallback ftpCallback = new UploadFileNameResumeCallback(this.Upload);
1002 return ftpCallback.BeginInvoke(fileName, resume, callback, null);
1003 }
1004 private delegate void UploadDirectoryCallback(String path,Boolean recurse);
1005 public System.IAsyncResult BeginUploadDirectory( String path,Boolean recurse, System.AsyncCallback callback )
1006 {
1007 UploadDirectoryCallback ftpCallback = new UploadDirectoryCallback(this.UploadDirectory);
1008 return ftpCallback.BeginInvoke(path, recurse, callback, null);
1009 }
1010 private delegate void UploadDirectoryPathRecurseMaskCallback(String path,Boolean recurse,String mask);
1011 public System.IAsyncResult BeginUploadDirectory( String path,Boolean recurse,String mask, System.AsyncCallback callback )
1012 {
1013 UploadDirectoryPathRecurseMaskCallback ftpCallback = new UploadDirectoryPathRecurseMaskCallback(this.UploadDirectory);
1014 return ftpCallback.BeginInvoke(path, recurse, mask, callback, null);
1015 }
1016 private delegate void DeleteFileCallback(String fileName);
1017 public System.IAsyncResult BeginDeleteFile( String fileName, System.AsyncCallback callback )
1018 {
1019 DeleteFileCallback ftpCallback = new DeleteFileCallback(this.DeleteFile);
1020 return ftpCallback.BeginInvoke(fileName, callback, null);
1021 }
1022 private delegate void RenameFileCallback(String oldFileName,String newFileName,Boolean overwrite);
1023 public System.IAsyncResult BeginRenameFile( String oldFileName,String newFileName,Boolean overwrite, System.AsyncCallback callback )
1024 {
1025 RenameFileCallback ftpCallback = new RenameFileCallback(this.RenameFile);
1026 return ftpCallback.BeginInvoke(oldFileName, newFileName, overwrite, callback, null);
1027 }
1028 private delegate void MakeDirCallback(String dirName);
1029 public System.IAsyncResult BeginMakeDir( String dirName, System.AsyncCallback callback )
1030 {
1031 MakeDirCallback ftpCallback = new MakeDirCallback(this.MakeDir);
1032 return ftpCallback.BeginInvoke(dirName, callback, null);
1033 }
1034 private delegate void RemoveDirCallback(String dirName);
1035 public System.IAsyncResult BeginRemoveDir( String dirName, System.AsyncCallback callback )
1036 {
1037 RemoveDirCallback ftpCallback = new RemoveDirCallback(this.RemoveDir);
1038 return ftpCallback.BeginInvoke(dirName, callback, null);
1039 }
1040 private delegate void ChangeDirCallback(String dirName);
1041 public System.IAsyncResult BeginChangeDir( String dirName, System.AsyncCallback callback )
1042 {
1043 ChangeDirCallback ftpCallback = new ChangeDirCallback(this.ChangeDir);
1044 return ftpCallback.BeginInvoke(dirName, callback, null);
1045 }
1046
1047 #endregion
1048 }
1049 }