-
-
Notifications
You must be signed in to change notification settings - Fork 657
/
Copy pathGetListing.cs
77 lines (54 loc) · 2.08 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
77
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 FtpObjectType.Directory:
Console.WriteLine("Directory! " + item.FullName);
Console.WriteLine("Modified date: " + conn.GetModifiedTime(item.FullName));
break;
case FtpObjectType.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 FtpObjectType.Link:
break;
}
}
}
}
public static async Task GetListingAsync() {
var token = new CancellationToken();
using (var conn = new AsyncFtpClient("127.0.0.1", "ftptest", "ftptest")) {
await conn.Connect(token);
// get a recursive listing of the files & folders in a specific folder
foreach (var item in await conn.GetListing("/htdocs", FtpListOption.Recursive, token)) {
switch (item.Type) {
case FtpObjectType.Directory:
Console.WriteLine("Directory! " + item.FullName);
Console.WriteLine("Modified date: " + await conn.GetModifiedTime(item.FullName, token));
break;
case FtpObjectType.File:
Console.WriteLine("File! " + item.FullName);
Console.WriteLine("File size: " + await conn.GetFileSize(item.FullName, -1, token));
Console.WriteLine("Modified date: " + await conn.GetModifiedTime(item.FullName, token));
Console.WriteLine("Chmod: " + await conn.GetChmod(item.FullName, token));
break;
case FtpObjectType.Link:
break;
}
}
}
}
}
}