Hi,
The FTPSample belowfrom Microsoft is very helpfull to get my application to send a file via FTP to a server.
Now our company is moving from FTP to SFTP and I need to update my application to use not only FTP but also SFTP.
I don't want to use any (paid) 3rd party applications.
I did find the FtpWebRequest.EnableSsl Property but there must be something more than just setting this property to true.
Can someone explain me how to change or what to add tothe current MS-FTPSample in VB so that I can also send via SFTP?
Thank you.
Micha.
This is the MS sample for FTP which I need to get on SFTP:
Private Sub Upload(ByVal fileName As String, ByVal uploadUrl As String)
Dim requestStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim uploadResponse As FtpWebResponse = Nothing
Try
Dim uploadRequest As FtpWebRequest = WebRequest.Create(uploadUrl)
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile
' UploadFile is not supported through an Http proxy
' so we disable the proxy for this request.
uploadRequest.Proxy =
Nothing
requestStream = uploadRequest.GetRequestStream()
fileStream = File.Open(fileName, FileMode.Open)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
requestStream.Write(buffer, 0, bytesRead)
End While
' The request stream must be closed before getting the response.
requestStream.Close()
uploadResponse = uploadRequest.GetResponse()
Console.WriteLine(
"Upload complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Finally
If uploadResponse IsNot Nothing Then
uploadResponse.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
If requestStream IsNot Nothing Then
requestStream.Close()
End If
End Try
End Sub