我的问题是我似乎不能让uri工作。错误消息显示“无效URI:无法确定URI的格式”。然后,当我尝试这一行Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create(ftpUri + ":" + port), FtpWebRequest)时,我得到了这个错误消息"The URI prefix is not recognized“
这是我所拥有的,当在filezilla中测试时,它工作得很完美:
主持人: sftp.icecream.com
用户名: softserve
密码:巧克力
端口: 22
目标文件夹: SoManyFlavors
下面是我的代码:
Private Sub FtpUploadFile(ByVal fileToUpload As String, ByVal ftpUri As String, ByVal userName As String, ByVal password As String, ByVal port As String)
Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create(ftpUri), FtpWebRequest)
Try
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile
ftpRequest.Credentials = New NetworkCredential(userName, password)
Dim bytes() As Byte = System.IO.File.ReadAllBytes(fileToUpload)
ftpRequest.ContentLength = bytes.Length
Using UploadStream As IO.Stream = ftpRequest.GetRequestStream()
UploadStream.Write(bytes, 0, bytes.Length)
UploadStream.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
End Sub我的电话:
FtpUploadFile("C:\Users\Desktop\icecream.txt", "sftp.icecream.com", "softserve", "chocolate", "22")
我还注意到ftp似乎有更多的选项,但我不确定哪一个最适合我的需求。
发布于 2017-06-15 06:19:25
你需要ftp://sftp.icecream.com", "softserve", "chocolate", "22`。
修复此错误后,您可能会收到另一个错误。.Net的FTP方法不支持SFTP,它看起来像是你的代码试图连接的那种协议。
https://stackoverflow.com/questions/44555250
复制相似问题