我刚刚在我的 VB 项目中安装了 WinSCP 库,因此我可以使用 FTPS 将应用程序文件传输到/从服务器传输。
但是,我为我缺乏知识而道歉,但是我如何让他们的示例代码在实际环境中工作?
我需要修改他们的代码以使用带有 TLS 的 FTP 而不是 SSH 上的 FTP,如下面的示例代码所示。
Imports WinSCP
Friend Class Example
Public Shared Function Main() As Integer
Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "example.com"
.UserName = "user"
.Password = "mypassword"
.SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="
End With
Using session As New Session
' Connect
session.Open(sessionOptions)
' Download files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary
Dim transferResult As TransferOperationResult
transferResult =
session.GetFiles("/home/user/*", "d:\download\", False, transferOptions)
' Throw on any error
transferResult.Check()
' Print results
For Each transfer In transferResult.Transfers
Console.WriteLine("Download of {0} succeeded", transfer.FileName)
Next
End Using
Return 0
Catch e As Exception
Console.WriteLine("Error: {0}", e)
Return 1
End Try
End Function
End Class
最佳答案
这应该有效:
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Ftp
.HostName = "example.com"
.UserName = "user"
.Password = "mypassword"
.FtpSecure = FtpSecure.Explicit
End With
关于VB.NET 2010 - 用于 FTPS 的 WinSCP 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63130825/