c# Winforms Application Logs Add In FTP server date by Date

  • Thread starter Thread starter VKS YADAV
  • Start date Start date
V

VKS YADAV

Guest
public static void AddLog(string msg)
{
// database method returns dataset/datareader, converted and passed to method as
// IEnumerable<string> data

string ftpServerIP = "***.***.**.***";
string targetFileName = "Logs\\" + "Client_" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "Log";
string username = "Username";
string password = "*********";

Uri uri = new Uri(String.Format("ftp://{0}/{1}", ftpServerIP, targetFileName));
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
reqFTP.Credentials = new NetworkCredential(username, password);
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;

MemoryStream stIn = new MemoryStream();
using (StreamWriter sw = new StreamWriter(stIn))
{
sw.WriteLine(DateTime.Now.ToString("dd-MM-yy hh:mm:ss tt => ") + msg);
sw.Flush();
using (Stream stOut = reqFTP.GetRequestStream())
{
stOut.Write(stIn.GetBuffer(), 0, (int)stIn.Length);
}
}

FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
response.Close();
}

Continue reading...
 
Back
Top