Ad

Xamarin Android FTP Authentication Problem On Startup

- 1 answer

I'm developing an Android application in C# language with Xamarin. In this application I need a service that starts after the device boot and upload files in a FTP server. If I start this service with a button click action all works good, but if I use a BroadcastReceiver and I intercept the BOOT_COMPLETED event to start the FTP connection, I receive this error:

ex.Message: The authentication or decryption has failed.
ex.StackTrace: at System.Net.FtpWebRequest.EndGetRequestStream (System.IAsyncResult asyncResult)
               at System.Net.FtpWebRequest.GetRequestStream ()
               at TestProject.FTPUtility.upload (System.String userName, System.String password, System.String sourceFile, System.String targetFile)

I don't understand why I receive the authentication or decryption error only if the service starts on startup. I tried also to start the connection only after a ping success (to wait the device internet connection) but nothing is changed.

Ad

Answer

I solved the problem with this line of code:

System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Ad
source: stackoverflow.com
Ad