Vb.net - 将文件上传到SFTP服务器 [英] Vb.net - upload a file to a SFTP server
问题描述
我想知道是否有人能指出正确的方向代码。我正在尝试将文件上传到SFTP服务器。刚刚发现WebRequestMethods没有这样做。 FTP没有麻烦但没有SFTP。
收到错误无法在Dim strz解析远程名称As System.IO.Stream = request.GetRequestStream()
正如你所看到的,它是相当标准的东西,但需要一些使用SFTP的建议或让我朝着正确的方向。
我尝试过:
Dim request As System.Net.FtpWebRequest = DirectCast(System.Net) .WebRequest.Create(ftp://sftp.mySFTPserver/Test.txt),System.Net.FtpWebRequest)
request.Credentials = New System.Net .NetworkCredential(sFtpUserName,sFTpPassword)
request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Dim file()As Byte = System.IO.File.ReadAllBytes(C:\ test.txt)
Dim strz As System.IO。 Stream = request.GetRequestStream()
尝试
strz.Write(file,0,file.Length)
strz.Close()
strz.Dispose()
Catch ex As Exception
MsgBox(Err.Description)
结束尝试
I wonder if anyone can point me in the correct direction code wise. I am trying to upload file to a SFTP server. Just found out that WebRequestMethods does not do this. FTP no bother but not SFTP.
Was getting the error "remote name could not be resolved at Dim strz As System.IO.Stream = request.GetRequestStream()
As you can see, it is pretty standard stuff but need a wee bit of advice using SFTP or put me in the right direction.
What I have tried:
Dim request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://sftp.mySFTPserver/Test.txt"), System.Net.FtpWebRequest)
request.Credentials = New System.Net.NetworkCredential(sFtpUserName, sFTpPassword)
request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Dim file() As Byte = System.IO.File.ReadAllBytes("C:\test.txt")
Dim strz As System.IO.Stream = request.GetRequestStream()
Try
strz.Write(file, 0, file.Length)
strz.Close()
strz.Dispose()
Catch ex As Exception
MsgBox(Err.Description)
End Try
推荐答案
SFTP客户端库 - SFTP.net [ ^ ]
这篇关于Vb.net - 将文件上传到SFTP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!