1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| Public Shared Function ValidateServerCertificate(ByVal sender As Object, ByVal certificate As X509Certificate2, ByVal chain As X509Chain, ByVal sslPolicyErrors__1 As SslPolicyErrors) As Boolean
Return True
End Function
Public Shared Sub Upload(ByVal fileName As String, ByVal userFTP As String, ByVal passwordFTP As String, ByVal adresseFTP As String)
Dim ftpServerIP As String = adresseFTP
Dim ftpUserID As String = userFTP
Dim ftpPassword As String = passwordFTP
'file name of local file
Dim fileInf As New FileInfo(fileName)
Dim reqFTP As FtpWebRequest
'Create FtpWebRequest object from the Uri
reqFTP = DirectCast(FtpWebRequest.Create(New Uri(("ftp://" & ftpServerIP & "/") + fileInf.Name)), FtpWebRequest)
'Provide WebPermission Credintials
reqFTP.Credentials = New NetworkCredential(ftpUserID, ftpPassword)
'By default KeepAlive is true, control connection is kept alive
reqFTP.KeepAlive = True
'Data transfer type.
reqFTP.UseBinary = False
'Enable the SSL
reqFTP.EnableSsl = True
'passive mode on
reqFTP.UsePassive = True
'Set the proxy to nothing
reqFTP.Proxy = Nothing
If reqFTP.EnableSsl = True Then
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
End If
'Partie Test
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory
Dim ResponsFTP As FtpWebResponse = reqFTP.GetResponse
end sub |
Partager