بله من خودم نوشتم اما می خوام ببینم دیگران چطور می نویسن.
این کد من 2 قسمت جدید شامل نه می شه.
private static bool UriServerIsUp(string UriStr)
{
try //Try to do the check without errors.
{
if (UriStr.ToUpper().StartsWith("FTP://")) //Check if the website procol are FTP.
{
FtpWebRequest fWebRequest = (FtpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
fWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
FtpWebResponse fWebResponse = (FtpWebResponse)fWebRequest.GetResponse(); //Get the server response.
if (fWebResponse.StatusCode == FtpStatusCode.OpeningData) //Get the server response code.
{
return true; //Return true if the response was 'OpeningData'.
}
else return false; //Return false if the response was not 'OpeningData'.
}
else //If is not FTP, check as HTTP protocol.
{
HttpWebRequest hWebRequest = (HttpWebRequest)WebRequest.Create(UriStr); //Create a request using the Uri string received by the method.
hWebRequest.Timeout = 10000; //Set the response timeout to 10 seconds.
HttpWebResponse hWebResponse = (HttpWebResponse)hWebRequest.GetResponse(); //Get the server response.
if (hWebResponse.StatusCode == HttpStatusCode.OK) //Get the server response code.
{
return true; //Return true if the response was 'OK'.
}
else return false; //Return false if the response was not 'OK'.
}
}
catch { return false; } //Return false if the there is an error with the request method.
}
foreach (string ServerUriString in
new object[] { "http://myfirstwebsite.com/regfile.reg", "ftp://ftp.mynewftp.com/regfile.reg", "http://mythserver.com/regfile.reg" }) //Make a simple forearch to check if the servers is working.
{
if (UriServerIsUp(ServerUriString)) //Check if the UriString has a valid status code.
{
DownloadAndInstallRegFile(ServerUriString); //Download and Install the registry file.
break; //Break the procedure one time that all the operation was completed successfully.
}
}