● -- ●
.■■■ -Imports System.IO
Imports System.Net
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
.■■■ -'設定 HTTPS 連線時,不要理會憑證的有效性問題, 於同 Class 新增此 Function
Private Function ValidateServerCertificate(ByVal sender As Object, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyerrors As SslPolicyErrors) As Boolean
'記得要載入兩個命名空間:System.Net.Security , System.Security.Cryptography.X509Certificates
Return True
End Function
.■■■ - 程式碼瀏覽FTP 檔名
Dim uriftp As String = "ftp://IP Address"
Dim sUserName As String = "UserName"
Dim sPassword As String = "Password"
Dim amyFtpWebRequest As FtpWebRequest = CType(FtpWebRequest.Create(uriftp), FtpWebRequest)
Dim amyNetworkCredential As NetworkCredential = New NetworkCredential(sUserName, sPassword)
amyFtpWebRequest.Credentials = amyNetworkCredential
amyFtpWebRequest.Method = WebRequestMethods.Ftp.ListDirectory
amyFtpWebRequest.EnableSsl = True
'設定 HTTPS 連線時,不要理會憑證的有效性問題
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
Dim amyFtpWebResponse As FtpWebResponse = CType(amyFtpWebRequest.GetResponse(), FtpWebResponse)
Dim a As Stream = amyFtpWebResponse.GetResponseStream()
Dim aReader As StreamReader
aReader = New StreamReader(a)
Dim aa As String = aReader.ReadToEnd '讀出所有檔愛名稱
Dim bb() As String = Split(aa.Trim, vbCrLf) '將string依各檔名存入陣列中
txtMsg.Text = ""
For i As Integer = 0 To UBound(bb) '下載各個檔案的名稱或自己寫下載
'MessageBox.Show(bb(i))
txtMsg.Text &= bb(i).ToString & vbNewLine
Next
.■■■ -
.■■■ -
.■■■ -
.■■■ -
.■■■ -
-
-
vb.net FTP Client SSL
on
0 意見:
張貼留言