forked from robinrodricks/FluentFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetListing.cs
76 lines (54 loc) · 2.19 KB
/
GetListing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using FluentFTP;
namespace Examples {
internal static class GetListingExample {
public static void GetListing() {
using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
conn.Connect();
// get a recursive listing of the files & folders in a specific folder
foreach (var item in conn.GetListing("/htdocs", FtpListOption.Recursive)) {
switch (item.Type) {
case FtpFileSystemObjectType.Directory:
Console.WriteLine("Directory! " + item.FullName);
Console.WriteLine("Modified date: " + conn.GetModifiedTime(item.FullName));
break;
case FtpFileSystemObjectType.File:
Console.WriteLine("File! " + item.FullName);
Console.WriteLine("File size: " + conn.GetFileSize(item.FullName));
Console.WriteLine("Modified date: " + conn.GetModifiedTime(item.FullName));
Console.WriteLine("Chmod: " + conn.GetChmod(item.FullName));
break;
case FtpFileSystemObjectType.Link:
break;
}
}
}
}
public static async Task GetListingAsync() {
var token = new CancellationToken();
using (var conn = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
await conn.ConnectAsync(token);
// get a recursive listing of the files & folders in a specific folder
foreach (var item in await conn.GetListingAsync("/htdocs", FtpListOption.Recursive, token)) {
switch (item.Type) {
case FtpFileSystemObjectType.Directory:
Console.WriteLine("Directory! " + item.FullName);
Console.WriteLine("Modified date: " + await conn.GetModifiedTimeAsync(item.FullName, FtpDate.Original, token));
break;
case FtpFileSystemObjectType.File:
Console.WriteLine("File! " + item.FullName);
Console.WriteLine("File size: " + await conn.GetFileSizeAsync(item.FullName, token));
Console.WriteLine("Modified date: " + await conn.GetModifiedTimeAsync(item.FullName, FtpDate.Original, token));
Console.WriteLine("Chmod: " + await conn.GetChmodAsync(item.FullName, token));
break;
case FtpFileSystemObjectType.Link:
break;
}
}
}
}
}
}