none
C# Create a txt file into a ftp server RRS feed

Answers

  • Hi Noam1248,

    Please try the following method.

     private void CreateFile(string textContent, string ftpUrl, string userName, string password)
            {
    
                // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl);
                request.Method = WebRequestMethods.Ftp.UploadFile;
    
                request.Credentials = new NetworkCredential(userName, password);
    
                // convert contents to byte.
                byte[] fileContents = Encoding.ASCII.GetBytes(textContent); ;
    
                request.ContentLength = fileContents.Length;
    
                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(fileContents, 0, fileContents.Length);
                }
    
                using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                {
                    Console.WriteLine($"Upload File Complete, status {response.StatusDescription}");
                }
    
            }

    #Usage:

    string ftpUsername = "yourusername";
    string ftpPassword = "yourpassword";
    CreateFile("essdfsdfasdfsdf", "ftp://ftpaddress/createfile.txt", ftpUsername, ftpPassword);

    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.


    Friday, November 23, 2018 1:25 AM
    Moderator

All replies

  • 1.Its my brother account...

    2.I just need to create a txt file thats it.

    Thursday, November 22, 2018 9:38 PM
  • 1.Its my brother account...

    2.I just need to create a txt file thats it.

    What do you want?! Don't answer that, it's a rhetorical question... We all just know you want to fool us. Always asking the same, and don't want to learn what we are telling you. It is hopeless. Creating a txt file was included in many of the examples we posted for you. 

    I just need to create a txt file thats it.

    No you don't! You need to learn the basics to understand what we are telling you! You have no idea of all the code we show you! Why you really want a program like this? Even if someone of us is coding you a ftp client, it's just copy pasted by you! So you are nothing more than a script kiddy! Do you want to be a script kiddy or do you want to become a real programmer? Then you have to learn!!! There is no way around it.




    • Edited by DerChris88 Thursday, November 22, 2018 10:03 PM
    Thursday, November 22, 2018 10:01 PM
  • Hi Noam1248,

    Please try the following method.

     private void CreateFile(string textContent, string ftpUrl, string userName, string password)
            {
    
                // Get the object used to communicate with the server.
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl);
                request.Method = WebRequestMethods.Ftp.UploadFile;
    
                request.Credentials = new NetworkCredential(userName, password);
    
                // convert contents to byte.
                byte[] fileContents = Encoding.ASCII.GetBytes(textContent); ;
    
                request.ContentLength = fileContents.Length;
    
                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(fileContents, 0, fileContents.Length);
                }
    
                using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                {
                    Console.WriteLine($"Upload File Complete, status {response.StatusDescription}");
                }
    
            }

    #Usage:

    string ftpUsername = "yourusername";
    string ftpPassword = "yourpassword";
    CreateFile("essdfsdfasdfsdf", "ftp://ftpaddress/createfile.txt", ftpUsername, ftpPassword);

    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.


    Friday, November 23, 2018 1:25 AM
    Moderator
  • Thanks!
    • Marked as answer by Noam1248 Saturday, November 24, 2018 1:50 PM
    • Unmarked as answer by Noam1248 Saturday, November 24, 2018 1:50 PM
    Friday, November 23, 2018 9:48 AM