AdvancedHMI Software
General Category => Support Questions => Topic started by: ddddd13 on June 21, 2019, 07:51:23 PM
-
Archie;
The code you wrote to read the FTP site worked great. But now they turned on the certificates and I get alarms stating that. The following is the code you wrote and the 5 lines I removed the ' from. With that I get a alarm, CertLocation is not declared. I tried DIM CertLocation as String and it returns an alarm text is not a string.
Private Sub FtpRead_Tomorrow()
'GET TODAYS DIRECTORY
'LOAD EPICOR DATA
' Get the object used to communicate with the server.
Dim request As Net.FtpWebRequest = DirectCast(WebRequest.Create(FtpAddress & Tomorrow & "*.*"), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails
'THE FOLLOWING 5 LINES WILL NEED TO BE TURNED ON IF CERTIFICATES ARE REQUIRED
request.EnableSsl = True
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(CertLocation.Text)
Dim certCollection As X509CertificateCollection = New X509CertificateCollection()
certCollection.Add(cert)
request.ClientCertificates = certCollection
' This example assumes the FTP site uses anonymous logon.
request.Credentials = New NetworkCredential(FtpUserName, FtpPassword)
Using response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
Dim responseStream As IO.Stream = response.GetResponseStream()
Using reader As New IO.StreamReader(responseStream)
RichTextBox1.Text = (reader.ReadToEnd())
End Using
End Using
End Sub
with that I get a alarm, CertLocation is not declared. I tried DIM CertLocation as String and it returns an alarm text is not a string.
Will this code handle certificates?
Thanks,
Dave
-
Archie;
In looking deeper at the code CertLocation.Text I assume is a location on my computer where the certifications are or an address where they are on the site I am trying to connect to?
Dave
-
The answer might be in either or both of the following links:
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate.createfromcertfile?view=netframework-4.8
https://stackoverflow.com/questions/899991/x509certificate-createfromcertfile-the-specified-network-password-is-not-corre
Or Archie might have something else...
-
Thanks for the links but...
It still doesn't make sense! I downloaded File Zilla, and it connects, allows me to upload and download files.
When it connects it shows initalizing tls, Verifying certificate, TLS connection established, Logged in.
By this I assume the certificate is established before the Login. Where is File Zilla getting the certificate from?
In looking at the code.
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(CertLocation)
CertLocation returns the error undefined
It looks like a certificate would be generated from the file located at CertLocation.
In running the program certmgr I can see the certificates, but I don't know which one File Zilla is using if any or what the location would be.
Lost again,
Dave
-
Try using Google search and check some of the results, like this one:
https://forum.filezilla-project.org/viewtopic.php?t=10212
That's pretty much what I do with your questions.
-
Who knows, maybe this might work for you:
https://community.boomi.com/s/article/retrievingftptlssslservercertificate
-
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(CertLocation)
I am no expert on this, but I interpret it as CertLocation would be the file path and name of the certificate:
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\MyCertificates\Cert1.cer")
-
I found the certificate in File Zilla. I put the following in the dim line. and I still get a path alarm.
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\Users\Dave\AppData\Roaming\FileZilla\trustedcerts.xml")
System.Security.Cryptography.CryptographicException
HResult=0x80070003
Message=The system cannot find the path specified.
Source=mscorlib
StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile(String filename)
at MfgControl.AdvancedHMI.MainForm.FtpRead_Tomorrow() in C:\AERO3\V399yBeta\AdvancedHMI\MainForm2.vb:line 130
at MfgControl.AdvancedHMI.MainForm.Timer2_Tick(Object sender, EventArgs e) in C:\AERO3\V399yBeta\AdvancedHMI\MainForm2.vb:line 213
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at MfgControl.AdvancedHMI.My.MyApplication.Main(String[] Args) in :line 81
I tried it your way too, same result. The following is the entire routine.
Private Sub FtpRead_Tomorrow()
'GET TODAYS DIRECTORY
'LOAD EPICOR DATA
' Get the object used to communicate with the server.
Dim request As Net.FtpWebRequest = DirectCast(WebRequest.Create(FtpAddress & "/*.*"), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails
'THE FOLLOWING 5 LINES WILL NEED TO BE TURNED ON IF CERTIFICATES ARE REQUIRED
request.EnableSsl = True
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\MyCertificates\Cert1.cer")
Dim certCollection As X509CertificateCollection = New X509CertificateCollection()
certCollection.Add(cert)
request.ClientCertificates = certCollection
' This example assumes the FTP site uses anonymous logon.
request.Credentials = New NetworkCredential(FtpUserName, FtpPassword)
Using response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
Dim responseStream As IO.Stream = response.GetResponseStream()
Using reader As New IO.StreamReader(responseStream)
RichTextBox1.Text = (reader.ReadToEnd())
End Using
End Using
Thanks,
Dave
-
It should specify an certificate file, so something like this:
Dim cert As X509Certificate = X509Certificate.CreateFromCertFile("C:\Users\Dave\AppData\Roaming\FileZilla\certificate.crt")
Using the directory where the actual .crt file is stored.
-
To anyone else trying to get a certificate do not use the example given at Boomi. They use a software called Openssl. It does not install correctly, has several different you tube examples of how to install it but they are all out of date, and has horrible documentation. Trust me I wasted the entire day.
Dave