- socket开源ftp类库代码:http://netftp.codeplex.com/
需要注意事项,如果以下代码出现乱码问题,可以设置其中的Encoding属性就可以。
用法示例:
1 using System; 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 4 using System.Text; 5 5 using System.Net.FtpClient; 6 6 using System.Net; 7 7 8 8 namespace AutoGathor.ConsoleUI 9 9 { 10 10 class Program 11 11 { 12 12 public static void Main(string[] args) 13 13 { 14 14 OMCInfo omc = new OMCInfo() 15 15 { 16 16 Id = Guid.NewGuid(), 17 17 DataType = AutoGathor.DataType.MR, 18 18 Name = "", 19 19 Port = 21, 20 20 Root = "/", 21 21 IP = "172.21.3.41", 22 22 Domain = "catt", 23 23 UserName = "username", 24 24 Password = "password" 25 25 }; 26 26 27 27 GathorTaskInfo task = new GathorTaskInfo() 28 28 { 29 29 OMC = omc, 30 30 Id = Guid.NewGuid(), 31 31 OMCId = omc.Id, 32 32 SavePath = "", 33 33 SourcePath = @"/2016-02-25", 34 34 StartTime = DateTime.Now, 35 35 Status = TaskStatus.DOING 36 36 }; 37 37 38 38 using (FtpClient conn = new FtpClient()) 39 39 { 40 40 conn.Host = task.OMC.IP; 41 41 conn.Credentials = new NetworkCredential(task.OMC.UserName, task.OMC.Password, task.OMC.Domain); 42 42 43 43 foreach (FtpListItem item in conn.GetListing(conn.GetWorkingDirectory(), FtpListOption.Modify | FtpListOption.Size)) 44 44 { 45 45 switch (item.Type) 46 46 { 47 47 case FtpFileSystemObjectType.Directory: 48 48 Console.WriteLine(item.Input); 49 49 50 50 foreach (FtpListItem _item in conn.GetListing(item.FullName, FtpListOption.Modify | FtpListOption.Size)) 51 51 { 52 52 switch (_item.Type) 53 53 { 54 54 case FtpFileSystemObjectType.Directory: 55 55 Console.WriteLine(_item.Input); 56 56 57 57 foreach (FtpListItem __item in conn.GetListing(_item.FullName, FtpListOption.Modify | FtpListOption.Size)) 58 58 { 59 59 switch (__item.Type) 60 60 { 61 61 case FtpFileSystemObjectType.Directory: 62 62 Console.WriteLine(__item.Input); 63 63 break; 64 64 case FtpFileSystemObjectType.File: 65 65 Console.WriteLine(__item.Input); 66 66 break; 67 67 } 68 68 } 69 69 break; 70 70 case FtpFileSystemObjectType.File: 71 71 Console.WriteLine(_item.Input); 72 72 break; 73 73 74 74 } 75 75 } 76 76 77 77 break; 78 78 case FtpFileSystemObjectType.File: 79 79 Console.WriteLine(item.Input); 80 80 break; 81 81 82 82 } 83 83 } 84 84 } 85 85 86 86 Console.ReadKey(); 87 87 } 88 88 } 89 89 }