5 using System.Net.Sockets;
6 using System.Diagnostics;
7 using System.Runtime.Remoting;
8 using System.Runtime.Remoting.Messaging;
11 * FTP Client library in C#
12 * Author: Jaimon Mathew
13 * mailto:jaimonmathew@rediffmail.com
14 * http://www.csharphelp.com/archives/archive9.html
16 * Addapted for use by Dan Glass 07/03/03
20 namespace ReactOS.CustomRevisionAction
23 public class FtpClient
26 public class FtpException : Exception
28 public FtpException(string message) : base(message){}
29 public FtpException(string message, Exception innerException) : base(message,innerException){}
32 private static int BUFFER_SIZE = 512;
33 private static Encoding ASCII = Encoding.ASCII;
35 private bool verboseDebugging = false;
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;
45 private int port = 21;
46 private int bytes = 0;
47 private int resultCode = 0;
49 private bool loggedin = false;
50 private bool binMode = false;
52 private Byte[] buffer = new Byte[BUFFER_SIZE];
53 private Socket clientSocket = null;
55 private int timeoutSeconds = 10;
58 /// Default contructor
66 /// <param name="server"></param>
67 /// <param name="username"></param>
68 /// <param name="password"></param>
69 public FtpClient(string server, string username, string password)
72 this.username = username;
73 this.password = password;
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)
86 this.username = username;
87 this.password = password;
88 this.timeoutSeconds = timeoutSeconds;
93 /// Display all communications to the debug log
95 public bool VerboseDebugging
99 return this.verboseDebugging;
103 this.verboseDebugging = value;
107 /// Remote server port. Typically TCP 21
121 /// Timeout waiting for a response from server, in seconds.
127 return this.timeoutSeconds;
131 this.timeoutSeconds = value;
135 /// Gets and Sets the name of the FTP server.
137 /// <returns></returns>
150 /// Gets and Sets the port number.
152 /// <returns></returns>
153 public int RemotePort
165 /// GetS and Sets the remote directory.
167 public string RemotePath
171 return this.remotePath;
175 this.remotePath = value;
180 /// Gets and Sets the username.
182 public string Username
186 return this.username;
190 this.username = value;
194 /// Gets and Set the password.
196 public string Password
200 return this.password;
204 this.password = value;
209 /// If the value of mode is true, set binary mode for downloads, else, Ascii mode.
211 public bool BinaryMode
219 if ( this.binMode == value ) return;
222 sendCommand("TYPE I");
225 sendCommand("TYPE A");
227 if ( this.resultCode != 200 ) throw new FtpException(result.Substring(4));
231 /// Login to the remote server.
235 if ( this.loggedin ) this.Close();
237 Debug.WriteLine("Opening connection to " + this.server, "FtpClient" );
239 IPAddress addr = null;
240 IPEndPoint ep = null;
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);
252 if ( this.clientSocket != null && this.clientSocket.Connected ) this.clientSocket.Close();
254 throw new FtpException("Couldn't connect to remote server",ex);
259 if(this.resultCode != 220)
262 throw new FtpException(this.result.Substring(4));
265 this.sendCommand( "USER " + username );
267 if( !(this.resultCode == 331 || this.resultCode == 230) )
270 throw new FtpException(this.result.Substring(4));
273 if( this.resultCode != 230 )
275 this.sendCommand( "PASS " + password );
277 if( !(this.resultCode == 230 || this.resultCode == 202) )
280 throw new FtpException(this.result.Substring(4));
284 this.loggedin = true;
286 Debug.WriteLine( "Connected to " + this.server, "FtpClient" );
288 this.ChangeDir(this.remotePath);
292 /// Close the FTP connection.
296 Debug.WriteLine("Closing connection to " + this.server, "FtpClient" );
298 if( this.clientSocket != null )
300 this.sendCommand("QUIT");
307 /// Return a string array containing the remote directory's file list.
309 /// <returns></returns>
310 public string[] GetFileList()
312 return this.GetFileList("*.*");
316 /// Return a string array containing the remote directory's file list.
318 /// <param name="mask"></param>
319 /// <returns></returns>
320 public string[] GetFileList(string mask)
322 if ( !this.loggedin ) this.Login();
324 Socket cSocket = createDataSocket();
326 this.sendCommand("NLST " + mask);
328 if(!(this.resultCode == 150 || this.resultCode == 125)) throw new FtpException(this.result.Substring(4));
332 DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);
334 while( timeout > DateTime.Now )
336 int bytes = cSocket.Receive(buffer, buffer.Length, 0);
337 this.message += ASCII.GetString(buffer, 0, bytes);
339 if ( bytes < this.buffer.Length ) break;
342 string[] msg = this.message.Replace("\r","").Split('\n');
346 if ( this.message.IndexOf( "No such file or directory" ) != -1 )
347 msg = new string[]{};
351 if ( this.resultCode != 226 )
352 msg = new string[]{};
353 // throw new FtpException(result.Substring(4));
358 public bool DirectoryExists(string directory)
362 ChangeDir(directory);
373 /// Return the size of a file.
375 /// <param name="fileName"></param>
376 /// <returns></returns>
377 public long GetFileSize(string fileName)
379 if ( !this.loggedin ) this.Login();
381 this.sendCommand("SIZE " + fileName);
384 if ( this.resultCode == 213 )
385 size = long.Parse(this.result.Substring(4));
388 throw new FtpException(this.result.Substring(4));
395 /// Download a file to the Assembly's local directory,
396 /// keeping the same file name.
398 /// <param name="remFileName"></param>
399 public void Download(string remFileName)
401 this.Download(remFileName,"",false);
405 /// Download a remote file to the Assembly's local directory,
406 /// keeping the same file name, and set the resume flag.
408 /// <param name="remFileName"></param>
409 /// <param name="resume"></param>
410 public void Download(string remFileName,Boolean resume)
412 this.Download(remFileName,"",resume);
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.
420 /// <param name="remFileName"></param>
421 /// <param name="locFileName"></param>
422 public void Download(string remFileName,string locFileName)
424 this.Download(remFileName,locFileName,false);
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.
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)
437 if ( !this.loggedin ) this.Login();
439 this.BinaryMode = true;
441 Debug.WriteLine("Downloading file " + remFileName + " from " + server + "/" + remotePath, "FtpClient" );
443 if (locFileName.Equals(""))
445 locFileName = remFileName;
448 FileStream output = null;
450 if ( !File.Exists(locFileName) )
451 output = File.Create(locFileName);
454 output = new FileStream(locFileName,FileMode.Open);
456 Socket cSocket = createDataSocket();
462 offset = output.Length;
466 this.sendCommand( "REST " + offset );
467 if ( this.resultCode != 350 )
469 //Server dosnt support resuming
471 Debug.WriteLine("Resuming not supported:" + result.Substring(4), "FtpClient" );
475 Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );
476 output.Seek( offset, SeekOrigin.Begin );
481 this.sendCommand("RETR " + remFileName);
483 if ( this.resultCode != 150 && this.resultCode != 125 )
485 throw new FtpException(this.result.Substring(4));
488 DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);
490 while ( timeout > DateTime.Now )
492 this.bytes = cSocket.Receive(buffer, buffer.Length, 0);
493 output.Write(this.buffer,0,this.bytes);
495 if ( this.bytes <= 0)
503 if ( cSocket.Connected ) cSocket.Close();
507 if( this.resultCode != 226 && this.resultCode != 250 )
508 throw new FtpException(this.result.Substring(4));
515 /// <param name="fileName"></param>
516 public void Upload(string fileName)
518 this.Upload(fileName,false);
523 /// Upload a file and set the resume flag.
525 /// <param name="fileName"></param>
526 /// <param name="resume"></param>
527 public void Upload(string fileName, bool resume)
529 if ( !this.loggedin ) this.Login();
531 Socket cSocket = null ;
538 this.BinaryMode = true;
540 offset = GetFileSize( Path.GetFileName(fileName) );
549 // open stream to read file
550 FileStream input = new FileStream(fileName,FileMode.Open);
552 if ( resume && input.Length < offset )
554 // different file size
555 Debug.WriteLine("Overwriting " + fileName, "FtpClient");
558 else if ( resume && input.Length == offset )
562 Debug.WriteLine("Skipping completed " + fileName + " - turn resume off to not detect.", "FtpClient");
566 // dont create untill we know that we need it
567 cSocket = this.createDataSocket();
571 this.sendCommand( "REST " + offset );
572 if ( this.resultCode != 350 )
574 Debug.WriteLine("Resuming not supported", "FtpClient");
579 this.sendCommand( "STOR " + Path.GetFileName(fileName) );
581 if ( this.resultCode != 125 && this.resultCode != 150 ) throw new FtpException(result.Substring(4));
585 Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );
587 input.Seek(offset,SeekOrigin.Begin);
590 Debug.WriteLine( "Uploading file " + fileName + " to " + remotePath, "FtpClient" );
592 while ((bytes = input.Read(buffer,0,buffer.Length)) > 0)
594 cSocket.Send(buffer, bytes, 0);
599 if (cSocket.Connected)
606 if( this.resultCode != 226 && this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
610 /// Upload a directory and its file contents
612 /// <param name="path"></param>
613 /// <param name="recurse">Whether to recurse sub directories</param>
614 public void UploadDirectory(string path, bool recurse)
616 this.UploadDirectory(path,recurse,"*.*");
620 /// Upload a directory and its file contents
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)
627 string[] dirs = path.Replace("/",@"\").Split('\\');
628 string rootDir = dirs[ dirs.Length - 1 ];
630 // make the root dir if it doed not exist
631 if ( this.GetFileList(rootDir).Length < 1 ) this.MakeDir(rootDir);
633 this.ChangeDir(rootDir);
635 foreach ( string file in Directory.GetFiles(path,mask) )
637 this.Upload(file,true);
641 foreach ( string directory in Directory.GetDirectories(path) )
643 this.UploadDirectory(directory,recurse,mask);
647 this.ChangeDir("..");
651 /// Delete a file from the remote FTP server.
653 /// <param name="fileName"></param>
654 public void DeleteFile(string fileName)
656 if ( !this.loggedin ) this.Login();
658 this.sendCommand( "DELE " + fileName );
660 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
662 Debug.WriteLine( "Deleted file " + fileName, "FtpClient" );
666 /// Rename a file on the remote FTP server.
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)
673 if ( !this.loggedin ) this.Login();
675 this.sendCommand( "RNFR " + oldFileName );
677 if ( this.resultCode != 350 ) throw new FtpException(this.result.Substring(4));
679 if ( !overwrite && this.GetFileList(newFileName).Length > 0 ) throw new FtpException("File already exists");
681 this.sendCommand( "RNTO " + newFileName );
683 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
685 Debug.WriteLine( "Renamed file " + oldFileName + " to " + newFileName, "FtpClient" );
689 /// Create a directory on the remote FTP server.
691 /// <param name="dirName"></param>
692 public void MakeDir(string dirName)
694 if ( !this.loggedin ) this.Login();
696 this.sendCommand( "MKD " + dirName );
698 if ( this.resultCode != 250 && this.resultCode != 257 ) throw new FtpException(this.result.Substring(4));
700 Debug.WriteLine( "Created directory " + dirName, "FtpClient" );
704 /// Delete a directory on the remote FTP server.
706 /// <param name="dirName"></param>
707 public void RemoveDir(string dirName)
709 if ( !this.loggedin ) this.Login();
711 this.sendCommand( "RMD " + dirName );
713 if ( this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));
715 Debug.WriteLine( "Removed directory " + dirName, "FtpClient" );
719 /// Change the current working directory on the remote FTP server.
721 /// <param name="dirName"></param>
722 public void ChangeDir(string dirName)
724 if( dirName == null || dirName.Equals(".") || dirName.Length == 0 )
729 if ( !this.loggedin ) this.Login();
731 this.sendCommand( "CWD " + dirName );
733 if ( this.resultCode != 250 )
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));
740 this.sendCommand( "PWD" );
742 if ( this.resultCode != 257 ) throw new FtpException(result.Substring(4));
744 // gonna have to do better than this....
745 this.remotePath = this.message.Split('"')[1];
747 Debug.WriteLine( "Current directory is " + this.remotePath, "FtpClient" );
753 private void readResponse()
756 this.result = this.readLine();
758 if ( this.result.Length > 3 )
759 this.resultCode = int.Parse( this.result.Substring(0,3) );
767 /// <returns></returns>
768 private string readLine()
772 this.bytes = clientSocket.Receive( this.buffer, this.buffer.Length, 0 );
773 this.message += ASCII.GetString( this.buffer, 0, this.bytes );
775 if ( this.bytes < this.buffer.Length )
781 string[] msg = this.message.Split('\n');
783 if ( this.message.Length > 2 )
784 this.message = msg[ msg.Length - 2 ];
787 this.message = msg[0];
790 if ( this.message.Length > 4 && !this.message.Substring(3,1).Equals(" ") ) return this.readLine();
792 if ( this.verboseDebugging )
794 for(int i = 0; i < msg.Length - 1; i++)
796 Debug.Write( msg[i], "FtpClient" );
806 /// <param name="command"></param>
807 private void sendCommand(String command)
809 if ( this.verboseDebugging ) Debug.WriteLine(command,"FtpClient");
811 Byte[] cmdBytes = Encoding.ASCII.GetBytes( ( command + "\r\n" ).ToCharArray() );
812 clientSocket.Send( cmdBytes, cmdBytes.Length, 0);
817 /// when doing data transfers, we need to open another socket for it.
819 /// <returns>Connected socket</returns>
820 private Socket createDataSocket()
822 this.sendCommand("PASV");
824 if ( this.resultCode != 227 ) throw new FtpException(this.result.Substring(4));
826 int index1 = this.result.IndexOf('(');
827 int index2 = this.result.IndexOf(')');
829 string ipData = this.result.Substring(index1+1,index2-index1-1);
831 int[] parts = new int[6];
833 int len = ipData.Length;
837 for (int i = 0; i < len && partCount <= 6; i++)
839 char ch = char.Parse( ipData.Substring(i,1) );
841 if ( char.IsDigit(ch) )
845 throw new FtpException("Malformed PASV result: " + result);
847 if ( ch == ',' || i+1 == len )
851 parts[partCount++] = int.Parse(buf);
856 throw new FtpException("Malformed PASV result (not supported?): " + this.result, ex);
861 string ipAddress = parts[0] + "."+ parts[1]+ "." + parts[2] + "." + parts[3];
863 int port = (parts[4] << 8) + parts[5];
865 Socket socket = null;
866 IPEndPoint ep = null;
870 socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
871 ep = new IPEndPoint(Dns.Resolve(ipAddress).AddressList[0], port);
877 if ( socket != null && socket.Connected ) socket.Close();
879 throw new FtpException("Can't connect to remote server", ex);
886 /// Always release those sockets.
888 private void cleanup()
890 if ( this.clientSocket!=null )
892 this.clientSocket.Close();
893 this.clientSocket = null;
895 this.loggedin = false;
907 /**************************************************************************************************************/
908 #region Async methods (auto generated)
911 WinInetApi.FtpClient ftp = new WinInetApi.FtpClient();
913 MethodInfo[] methods = ftp.GetType().GetMethods(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Public);
915 foreach ( MethodInfo method in methods )
919 foreach ( ParameterInfo i in method.GetParameters() )
921 param += i.ParameterType.Name + " " + i.Name + ",";
922 values += i.Name + ",";
926 Debug.WriteLine("private delegate " + method.ReturnType.Name + " " + method.Name + "Callback(" + param.TrimEnd(',') + ");");
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);
943 private delegate void LoginCallback();
944 public System.IAsyncResult BeginLogin( System.AsyncCallback callback )
946 LoginCallback ftpCallback = new LoginCallback( this.Login);
947 return ftpCallback.BeginInvoke(callback, null);
949 private delegate void CloseCallback();
950 public System.IAsyncResult BeginClose( System.AsyncCallback callback )
952 CloseCallback ftpCallback = new CloseCallback( this.Close);
953 return ftpCallback.BeginInvoke(callback, null);
955 private delegate String[] GetFileListCallback();
956 public System.IAsyncResult BeginGetFileList( System.AsyncCallback callback )
958 GetFileListCallback ftpCallback = new GetFileListCallback( this.GetFileList);
959 return ftpCallback.BeginInvoke(callback, null);
961 private delegate String[] GetFileListMaskCallback(String mask);
962 public System.IAsyncResult BeginGetFileList( String mask, System.AsyncCallback callback )
964 GetFileListMaskCallback ftpCallback = new GetFileListMaskCallback(this.GetFileList);
965 return ftpCallback.BeginInvoke(mask, callback, null);
967 private delegate Int64 GetFileSizeCallback(String fileName);
968 public System.IAsyncResult BeginGetFileSize( String fileName, System.AsyncCallback callback )
970 GetFileSizeCallback ftpCallback = new GetFileSizeCallback(this.GetFileSize);
971 return ftpCallback.BeginInvoke(fileName, callback, null);
973 private delegate void DownloadCallback(String remFileName);
974 public System.IAsyncResult BeginDownload( String remFileName, System.AsyncCallback callback )
976 DownloadCallback ftpCallback = new DownloadCallback(this.Download);
977 return ftpCallback.BeginInvoke(remFileName, callback, null);
979 private delegate void DownloadFileNameResumeCallback(String remFileName,Boolean resume);
980 public System.IAsyncResult BeginDownload( String remFileName,Boolean resume, System.AsyncCallback callback )
982 DownloadFileNameResumeCallback ftpCallback = new DownloadFileNameResumeCallback(this.Download);
983 return ftpCallback.BeginInvoke(remFileName, resume, callback, null);
985 private delegate void DownloadFileNameFileNameCallback(String remFileName,String locFileName);
986 public System.IAsyncResult BeginDownload( String remFileName,String locFileName, System.AsyncCallback callback )
988 DownloadFileNameFileNameCallback ftpCallback = new DownloadFileNameFileNameCallback(this.Download);
989 return ftpCallback.BeginInvoke(remFileName, locFileName, callback, null);
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 )
994 DownloadFileNameFileNameResumeCallback ftpCallback = new DownloadFileNameFileNameResumeCallback(this.Download);
995 return ftpCallback.BeginInvoke(remFileName, locFileName, resume, callback, null);
997 private delegate void UploadCallback(String fileName);
998 public System.IAsyncResult BeginUpload( String fileName, System.AsyncCallback callback )
1000 UploadCallback ftpCallback = new UploadCallback(this.Upload);
1001 return ftpCallback.BeginInvoke(fileName, callback, null);
1003 private delegate void UploadFileNameResumeCallback(String fileName,Boolean resume);
1004 public System.IAsyncResult BeginUpload( String fileName,Boolean resume, System.AsyncCallback callback )
1006 UploadFileNameResumeCallback ftpCallback = new UploadFileNameResumeCallback(this.Upload);
1007 return ftpCallback.BeginInvoke(fileName, resume, callback, null);
1009 private delegate void UploadDirectoryCallback(String path,Boolean recurse);
1010 public System.IAsyncResult BeginUploadDirectory( String path,Boolean recurse, System.AsyncCallback callback )
1012 UploadDirectoryCallback ftpCallback = new UploadDirectoryCallback(this.UploadDirectory);
1013 return ftpCallback.BeginInvoke(path, recurse, callback, null);
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 )
1018 UploadDirectoryPathRecurseMaskCallback ftpCallback = new UploadDirectoryPathRecurseMaskCallback(this.UploadDirectory);
1019 return ftpCallback.BeginInvoke(path, recurse, mask, callback, null);
1021 private delegate void DeleteFileCallback(String fileName);
1022 public System.IAsyncResult BeginDeleteFile( String fileName, System.AsyncCallback callback )
1024 DeleteFileCallback ftpCallback = new DeleteFileCallback(this.DeleteFile);
1025 return ftpCallback.BeginInvoke(fileName, callback, null);
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 )
1030 RenameFileCallback ftpCallback = new RenameFileCallback(this.RenameFile);
1031 return ftpCallback.BeginInvoke(oldFileName, newFileName, overwrite, callback, null);
1033 private delegate void MakeDirCallback(String dirName);
1034 public System.IAsyncResult BeginMakeDir( String dirName, System.AsyncCallback callback )
1036 MakeDirCallback ftpCallback = new MakeDirCallback(this.MakeDir);
1037 return ftpCallback.BeginInvoke(dirName, callback, null);
1039 private delegate void RemoveDirCallback(String dirName);
1040 public System.IAsyncResult BeginRemoveDir( String dirName, System.AsyncCallback callback )
1042 RemoveDirCallback ftpCallback = new RemoveDirCallback(this.RemoveDir);
1043 return ftpCallback.BeginInvoke(dirName, callback, null);
1045 private delegate void ChangeDirCallback(String dirName);
1046 public System.IAsyncResult BeginChangeDir( String dirName, System.AsyncCallback callback )
1048 ChangeDirCallback ftpCallback = new ChangeDirCallback(this.ChangeDir);
1049 return ftpCallback.BeginInvoke(dirName, callback, null);