vb.net - 如何在vb.net中从SFTP下载文件

标签 vb.net ssh

我正在尝试使用Renci.SshNet.Sftp 中的类通过VB.NET 从SFTP 服务器下载文件。这是我的代码:

Using client As New SftpClient("server", "test", "test")
    client.Connect()
    Dim list As List(Of SftpFile) = CType(client.ListDirectory(""), List(Of SftpFile))
    '------------------------
    For Each sFile As SftpFile In list
        Console.WriteLine(sFile.Name)
        client.DownloadFile("path", ????)
    Next
    client.Disconnect()
End Using

使用此代码,我可以连接到服务器并查看该文件,但无法下载它。我不知道如何调用 DownloadFile 方法。

最佳答案

DownloadFile 方法的第二个参数采用一个流。因此,您只需创建一个新的 FileStream 将下载的数据写入新文件,如下所示:

Using fs As New FileStream(localFilePath, FileMode.CreateNew, FileAccess.Write)
    client.DownloadFile(serverFilePath, fs)
End Using

关于vb.net - 如何在vb.net中从SFTP下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34723954/

相关文章:

c# - BitConverter 类中 IsLittleEndian 的用例是什么?

c# - 如何将此 linq.expression 从 C# 转换为 VB?

mysql - vb.net sql查询计数

c# - 为什么我们需要连接字符串?

linux - 如何安装git lfs

ssh - 安塞 bool : SSH Error: ControlPath too long

linux - SSH 在 'debug1: SSH2_MSG_KEXINIT sent' 挂起

python - 在 IPython 笔记本中请求密码

c# - C# 中的 ProductName 和 CompanyName

azure - ##[错误]未处理的: handle is not a Buffer CopyFilesOverSSH in Azure DevOps build pipeline