forked from robinrodricks/FluentFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add VB examples matching CS examples
- Loading branch information
1 parent
348d4f7
commit 92e0fbc
Showing
37 changed files
with
1,499 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,41 @@ | ||
Public Class Connect | ||
Imports System | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
End Class | ||
Namespace Examples | ||
Friend Module ConnectExample | ||
Sub Connect() | ||
Using conn = New FtpClient() | ||
conn.Host = "localhost" | ||
conn.Credentials = New NetworkCredential("ftptest", "ftptest") | ||
conn.Connect() | ||
End Using | ||
End Sub | ||
|
||
Sub ConnectAlt() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.Connect() | ||
End Using | ||
End Sub | ||
|
||
Async Function ConnectAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient() | ||
conn.Host = "localhost" | ||
conn.Credentials = New NetworkCredential("ftptest", "ftptest") | ||
Await conn.ConnectAsync(token) | ||
End Using | ||
End Function | ||
|
||
Async Function ConnectAsyncAlt() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
Await conn.ConnectAsync(token) | ||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Imports System | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module ConnectFTPSExample | ||
Sub ConnectFTPS() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.EncryptionMode = FtpEncryptionMode.Explicit | ||
conn.ValidateAnyCertificate = True | ||
conn.Connect() | ||
End Using | ||
End Sub | ||
|
||
Async Function ConnectFTPSAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.EncryptionMode = FtpEncryptionMode.Explicit | ||
conn.ValidateAnyCertificate = True | ||
Await conn.ConnectAsync(token) | ||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Imports System | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module ConnectFTPSCertificateExample | ||
Sub ConnectFTPSCertificate() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.EncryptionMode = FtpEncryptionMode.Explicit | ||
AddHandler conn.ValidateCertificate, New FtpSslValidation(AddressOf OnValidateCertificate) | ||
conn.Connect() | ||
End Using | ||
End Sub | ||
|
||
Async Function ConnectFTPSCertificateAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.EncryptionMode = FtpEncryptionMode.Explicit | ||
AddHandler conn.ValidateCertificate, New FtpSslValidation(AddressOf OnValidateCertificate) | ||
Await conn.ConnectAsync(token) | ||
End Using | ||
End Function | ||
|
||
Private Sub OnValidateCertificate(ByVal control As FtpClient, ByVal e As FtpSslValidationEventArgs) | ||
If e.PolicyErrors <> System.Net.Security.SslPolicyErrors.None Then | ||
' invalid cert, do you want to accept it? | ||
' e.Accept = True | ||
Else | ||
e.Accept = True | ||
End If | ||
End Sub | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Imports System | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module CreateDirectoryExample | ||
Sub CreateDirectory() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.Connect() | ||
conn.CreateDirectory("/test/path/that/should/be/created", True) | ||
End Using | ||
End Sub | ||
|
||
Async Function CreateDirectoryAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
Await conn.ConnectAsync(token) | ||
Await conn.CreateDirectoryAsync("/test/path/that/should/be/created", True, token) | ||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Imports System | ||
Imports System.Diagnostics | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module DebugExample | ||
Private Sub LogToConsole() | ||
FtpTrace.AddListener(New ConsoleTraceListener()) | ||
End Sub | ||
|
||
Private Sub LogToFile() | ||
FtpTrace.AddListener(New TextWriterTraceListener("log_file.txt")) | ||
End Sub | ||
|
||
Private Class CustomTraceListener | ||
Inherits TraceListener | ||
|
||
Public Overrides Sub Write(ByVal message As String) | ||
Console.Write(message) | ||
End Sub | ||
|
||
Public Overrides Sub WriteLine(ByVal message As String) | ||
Console.WriteLine(message) | ||
End Sub | ||
End Class | ||
|
||
Private Sub LogToCustomListener() | ||
FtpTrace.AddListener(New CustomTraceListener()) | ||
End Sub | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module DeleteDirectoryExample | ||
Sub DeleteDirectory() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.Connect() | ||
|
||
' Remove the directory And all files And subdirectories inside it | ||
conn.DeleteDirectory("/path/to/directory") | ||
|
||
End Using | ||
End Sub | ||
|
||
Async Function DeleteDirectoryAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
Await conn.ConnectAsync(token) | ||
|
||
' Remove the directory And all files And subdirectories inside it | ||
Await conn.DeleteDirectoryAsync("/path/to/directory", token) | ||
|
||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Imports System | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module DeleteFileExample | ||
Sub DeleteFile() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.Connect() | ||
conn.DeleteFile("/full/or/relative/path/to/file") | ||
End Using | ||
End Sub | ||
|
||
Async Function DeleteDirectoryAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
Await conn.ConnectAsync(token) | ||
Await conn.DeleteFileAsync("/full/or/relative/path/to/file") | ||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Imports System | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module DereferenceLink | ||
Sub DereferenceLinkExample() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.Connect() | ||
conn.MaximumDereferenceCount = 20 | ||
|
||
For Each item In conn.GetListing(Nothing, FtpListOption.ForceList Or FtpListOption.Modify) | ||
Console.WriteLine(item) | ||
|
||
If item.Type = FtpFileSystemObjectType.Link AndAlso item.LinkTarget IsNot Nothing Then | ||
item.LinkObject = conn.DereferenceLink(item) | ||
|
||
If item.LinkObject IsNot Nothing Then | ||
Console.WriteLine(item.LinkObject) | ||
End If | ||
End If | ||
Next | ||
|
||
For Each item In conn.GetListing(Nothing, FtpListOption.ForceList Or FtpListOption.Modify Or FtpListOption.DerefLinks) | ||
Console.WriteLine(item) | ||
|
||
If item.Type = FtpFileSystemObjectType.Link AndAlso item.LinkObject IsNot Nothing Then | ||
Console.WriteLine(item.LinkObject) | ||
End If | ||
Next | ||
End Using | ||
End Sub | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Imports System | ||
Imports System.Net | ||
Imports System.Threading | ||
Imports System.Threading.Tasks | ||
Imports FluentFTP | ||
|
||
Namespace Examples | ||
Friend Module DirectoryExistsExample | ||
Sub DirectoryExists() | ||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
conn.Connect() | ||
|
||
If conn.DirectoryExists("/full/or/relative/path") Then | ||
' do something | ||
End If | ||
|
||
End Using | ||
End Sub | ||
|
||
Async Function DirectoryExistsAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using conn = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
Await conn.ConnectAsync(token) | ||
|
||
If Await conn.DirectoryExistsAsync("/full/or/relative/path") Then | ||
' do something | ||
End If | ||
|
||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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 DownloadDirectoryExample | ||
Sub DownloadDirectory() | ||
Using ftp = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
ftp.Connect() | ||
|
||
' download a folder And all its files | ||
ftp.DownloadDirectory("C:\website\logs\", "/public_html/logs", FtpFolderSyncMode.Update) | ||
|
||
' download a folder And all its files, And delete extra files on disk | ||
ftp.DownloadDirectory("C:\website\dailybackup\", "/public_html/", FtpFolderSyncMode.Mirror) | ||
|
||
End Using | ||
End Sub | ||
|
||
Async Function DownloadDirectoryAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using ftp = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
Await ftp.ConnectAsync(token) | ||
|
||
' download a folder And all its files | ||
Await ftp.DownloadDirectoryAsync("C:\website\logs\", "/public_html/logs", FtpFolderSyncMode.Update) | ||
|
||
' download a folder And all its files, And delete extra files on disk | ||
Await ftp.DownloadDirectoryAsync("C:\website\dailybackup\", "/public_html/", FtpFolderSyncMode.Mirror) | ||
|
||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 DownloadDirectoryWithRulesExample | ||
Sub DownloadDirectoryWithRules() | ||
Using ftp = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
ftp.Connect() | ||
|
||
|
||
' download 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.DownloadDirectory("C:\website\attachments\", "/public_html/attachments", FtpFolderSyncMode.Update, FtpLocalExists.Skip, FtpVerify.None, rules) | ||
|
||
|
||
' download 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.DownloadDirectory("C:\project\src\", "/project/src", FtpFolderSyncMode.Update, FtpLocalExists.Skip, FtpVerify.None, rules2) | ||
|
||
|
||
End Using | ||
End Sub | ||
|
||
Async Function DownloadDirectoryWithRulesAsync() As Task | ||
Dim token = New CancellationToken() | ||
|
||
Using ftp = New FtpClient("127.0.0.1", "ftptest", "ftptest") | ||
Await ftp.ConnectAsync(token) | ||
|
||
|
||
' download 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.DownloadDirectoryAsync("C:\website\attachments\", "/public_html/attachments", FtpFolderSyncMode.Update, FtpLocalExists.Skip, FtpVerify.None, rules) | ||
|
||
|
||
' download 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.DownloadDirectoryAsync("C:\project\src\", "/project/src", FtpFolderSyncMode.Update, FtpLocalExists.Skip, FtpVerify.None, rules2) | ||
|
||
|
||
End Using | ||
End Function | ||
End Module | ||
End Namespace |
Oops, something went wrong.