VB.NET 2010 - 用于 FTPS 的 WinSCP 包

标签 vb.net ssl sftp winscp ftps

我刚刚在我的 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/

相关文章:

VB.NET |获取当前用户配置文件文件夹

ssl - TLS 相互认证 : null cert chain (C client -> Java server) unless cafile points to same file as cert

c# - SSH.NET SFTP 客户端在连接到 Cerberus SFTP 服务器时给出 "Path does not exists"

php发送文件到sftp

java - JSch 从字符串中添加私钥

VB.NET Microsoft Office 互操作书签

Vb.net Property 获取和设置没有私有(private)变量的值

c# - 带有 .Years 和 .Months 的实时时间跨度对象

security - Kafka SSL 安全设置导致问题

python - 如何使用python找出http和ssl版本