/// <summary> /// Gets the remote launcher version. /// </summary> /// <returns>The remote launcher version.</returns> public Version GetRemoteLauncherVersion() { string remoteVersionPath = String.Format("{0}/launcher/LauncherVersion.txt", Config.GetFTPUrl()); string remoteVersion = ReadFTPFile(remoteVersionPath); return(Version.Parse(remoteVersion)); }
/// <summary> /// Determines whether this instance can connect to the FTP server. Run as little as possible, since it blocks the main thread while checking. /// </summary> /// <returns><c>true</c> if this instance can connect to the FTP server; otherwise, <c>false</c>.</returns> public bool CanConnectToFTP() { bool bCanConnectToFTP; string FTPURL = Config.GetFTPUrl(); string FTPUserName = Config.GetFTPUsername(); string FTPPassword = Config.GetFTPPassword(); try { FtpWebRequest plainRequest = (FtpWebRequest)FtpWebRequest.Create(FTPURL); plainRequest.Credentials = new NetworkCredential(FTPUserName, FTPPassword); plainRequest.Method = WebRequestMethods.Ftp.ListDirectory; plainRequest.Timeout = 8000; try { WebResponse response = plainRequest.GetResponse(); plainRequest.Abort(); response.Close(); bCanConnectToFTP = true; } catch (WebException wex) { Console.WriteLine("WebException in CanConnectToFTP(): " + wex.Message); Console.WriteLine(FTPURL); plainRequest.Abort(); bCanConnectToFTP = false; } } catch (WebException wex) { //case where FTP URL in config is not valid Console.WriteLine("WebException CanConnectToFTP() (Invalid URL): " + wex.Message); bCanConnectToFTP = false; return(bCanConnectToFTP); } if (!bCanConnectToFTP) { Console.WriteLine("Failed to connect to FTP server at: {0}", Config.GetFTPUrl()); bCanConnectToFTP = false; } return(bCanConnectToFTP); }