Vb 2005 ftp ssl
I wrote a small ftp program to transfer a file FTP.
I want to use FTP over SSL, but when I enable the SSL property, I still get connection errors. My connection script worked fine as ftp, but I'm not sure if I have to exchange a certificate now, or if it should be automatic?
Anyone know where i can find some sample code for this??
Thanks :confused:
..I can submit the code, and i dont care what i connnect to for testing as long as its ssl-ftp.
# 2 Re: Vb 2005 ftp ssl
Imports System.Net
Imports System.IO
Imports System.Security.Cryptography.X509Certificates
'System.Net.FtpWebRequest.EnableSsl
Public Class Form1
Private Sub Uploader1(ByVal source As String, ByVal target As String, _
ByVal credential As NetworkCredential)
Dim request As FtpWebRequest = _
DirectCast(WebRequest.Create(target), FtpWebRequest)
Dim tempCert As X509CertificateCollection
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = credential
request.EnableSsl = True '***********************
tempCert = request.ClientCertificates
request.ClientCertificates = tempCert
Dim reader As New FileStream(source, FileMode.Open)
Dim buffer(Convert.ToInt32(reader.Length - 1)) As Byte
reader.Read(buffer, 0, buffer.Length)
reader.Close()
request.ContentLength = buffer.Length
Dim stream As Stream = request.GetRequestStream
stream.Write(buffer, 0, buffer.Length)
stream.Close()
Dim response As FtpWebResponse = DirectCast(request.GetResponse, FtpWebResponse)
MsgBox((response.ExitMessage))
response.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim credential As New NetworkCredential("test", "test")
Uploader1("c:\text1.txt", "ftp://put server here/text1.txt", credential)
End Sub
End Class