Reputation:
My problem is I can’t seem to get the uri to work. The Error message says “Invalid URI: The format of the URI could not be determined”. Then I get this error message "The URI prefix is not recognized" when I try this line Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create(ftpUri + ":" + port), FtpWebRequest)
Here’s what I have, and it works perfect when tested in filezilla:
Host: sftp.icecream.com
Username: softserve
Password: chocolate
Port: 22
destination folder: SoManyFlavors
here’s my code:
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
my call:
FtpUploadFile("C:\Users\Desktop\icecream.txt", "sftp.icecream.com", "softserve", "chocolate", "22")
I also noticed there seem to be a few more options for ftp, but I’m not sure which one is best for my needs.
Upvotes: 0
Views: 1284
Reputation: 2197
You need to specify the FTP protocol. Change your call to FtpUploadFile("C:\Users\Desktop\icecream.txt", "ftp://sftp.icecream.com", "softserve", "chocolate", "22")
.
You might get another error after fixing this error. The .Net FTP methods don't support SFTP, which is the kind of protocol it looks like you're code is trying to connect with.
Upvotes: 3