gpt4 book ai didi

VB.NET 2010 - 用于 FTPS 的 WinSCP 包

转载 作者:行者123 更新时间:2023-12-04 22:38:49 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com