Web Service Retrieve and Publish Web IP Address
Web Service Retrieve and Publish Web IP Address
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://www.network-tools.com");
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
String __SearchString =
"<input id=\"field\" name=\"host\" type=\"text\" value =\"(.*)\" size=\"85\" />";
System.Text.RegularExpressions.Regex _regex =
new System.Text.RegularExpressions.Regex(__SearchString);
return _regex.Match(sb.ToString()).Result("$1").ToString();
}
[WebMethod(Description = "Publish Server IP Address")]
public string publishServerIP()
{
string IP = GetServerIPAddress();
string company = "{your company ftp information goes here}";
string fileName = "{your filename goes here}";
string userName = "{your userName goes here} ";
string password = "{your passWord goes here}";
FtpWebRequest putFTP;
putFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPAddress));
putFTP.Credentials = new NetworkCredential( userName, password);
putFTP.KeepAlive = false;
putFTP.Method = WebRequestMethods.Ftp.UploadFile;
putFTP.UseBinary = true;
putFTP.UsePassive = true;
putFTP.ContentLength = encoding.GetBytes(IP).Length;
try
{
Stream strm = putFTP.GetRequestStream();
strm.Write(buff, 0, buff.Length);
strm.Close();
string logMessage = String.Format("{0} {1} {2}",
DateTime.Now.ToString(),
FTPAddress.ToString(),
"Failure");
tw.WriteLine(logMessage.ToString());
tw.Flush();
tw.Close();
return "Success";
}
catch (Exception ex)
{
string logMessage = String.Format("{0} {1} {2}",
DateTime.Now.ToString(),
FTPAddress.ToString(),
"Failure");
tw.WriteLine(logMessage.ToString());
tw.WriteLine(ex.ToString());
tw.Flush();
tw.Close();
return "Failure";
}
}