-
-
Notifications
You must be signed in to change notification settings - Fork 660
/
UploadDirectoryWithRules.vb
63 lines (48 loc) · 2.26 KB
/
UploadDirectoryWithRules.vb
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
Imports System
Imports System.Collections.Generic
Imports System.Net
Imports System.Threading
Imports System.Threading.Tasks
Imports FluentFTP
Imports FluentFTP.Rules
Namespace Examples
Friend Module UploadDirectoryWithRulesExample
Sub UploadDirectoryWithRules()
Using ftp = New FtpClient("127.0.0.1", "ftptest", "ftptest")
ftp.Connect()
' upload only PDF files under 1 GB from a folder, by using the rule engine
Dim rules = New List(Of FtpRule) From {
New FtpFileExtensionRule(True, New List(Of String) From { ' only allow PDF files
"pdf"
}),
New FtpSizeRule(FtpOperator.LessThan, 1000000000) ' only allow files <1 GB
}
ftp.UploadDirectory("C:\website\attachments\", "/public_html/attachments", FtpFolderSyncMode.Update, FtpRemoteExists.Skip, FtpVerify.None, rules)
' upload all files from a folder, but skip the sub-directories named `.git`, `.svn`, `node_modules` etc
Dim rules2 = New List(Of FtpRule) From {
New FtpFolderNameRule(False, FtpFolderNameRule.CommonBlacklistedFolders)
}
ftp.UploadDirectory("C:\project\src\", "/project/src", FtpFolderSyncMode.Update, FtpRemoteExists.Skip, FtpVerify.None, rules2)
End Using
End Sub
Async Function UploadDirectoryWithRulesAsync() As Task
Dim token = New CancellationToken()
Using ftp = New AsyncFtpClient("127.0.0.1", "ftptest", "ftptest")
Await ftp.Connect(token)
' upload only PDF files under 1 GB from a folder, by using the rule engine
Dim rules = New List(Of FtpRule) From {
New FtpFileExtensionRule(True, New List(Of String) From {' only allow PDF files
"pdf"
}),
New FtpSizeRule(FtpOperator.LessThan, 1000000000)' only allow files <1 GB
}
Await ftp.UploadDirectory("C:\website\attachments\", "/public_html/attachments", FtpFolderSyncMode.Update, FtpRemoteExists.Skip, FtpVerify.None, rules)
' upload all files from a folder, but skip the sub-directories named `.git`, `.svn`, `node_modules` etc
Dim rules2 = New List(Of FtpRule) From {
New FtpFolderNameRule(False, FtpFolderNameRule.CommonBlacklistedFolders)
}
Await ftp.UploadDirectory("C:\project\src\", "/project/src", FtpFolderSyncMode.Update, FtpRemoteExists.Skip, FtpVerify.None, rules2)
End Using
End Function
End Module
End Namespace