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

  • Question

  • 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();
            }
    Tuesday, February 5, 2019 8:23 AM

All replies

  • The purpose of the post is what?
    Tuesday, February 5, 2019 11:42 AM
  • What part of your code are you having a problem with, and what are you trying to do that it's not doing correctly? IOW, what exactly is your question????

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Tuesday, February 5, 2019 3:44 PM
    Moderator
  • Hi VKS YADAV,

    If you want to execute the method every day, I would suggest that you could create a windows Task Scheduler, which run the Winforms application every day. 

    If I misunderstand the issue, please describe it in detailed, what is the issue, how to reproduce it, detailed error message, etc.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 6, 2019 2:51 AM
    Moderator