How to download files in to the pc with out the folder and with FTP RRS feed

All replies

    • Proposed as answer by Castorix31 Sunday, December 30, 2018 12:54 PM
    Saturday, December 29, 2018 10:41 AM
  • Something else?
    Sunday, December 30, 2018 12:40 PM
  • Hi Noam1248,

    Thank you for posting here.

    For your question, you want to download files from the ftp.

    Here is my test code.

    private void button1_Click(object sender, EventArgs e)
                string username = "xxx";
                string password = "xxx";
                string location = @"ftp://test/test1.txt";
                Ftpdownloadfile(location, username, password);
            private void  Ftpdownloadfile(string to_uri, string user_name, string password)
                FtpWebRequest request =
                request.Method = WebRequestMethods.Ftp.DownloadFile;
                request.Credentials =
                    new NetworkCredential(user_name, password);
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                Stream ftpStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(ftpStream);
                string filestr = reader.ReadToEnd();
                string savepath = @"D:\save\new.txt";
                if (File.Exists(savepath))
                using (FileStream fs = File.Create(savepath))
                    Byte[] info = new UTF8Encoding(true).GetBytes(filestr);
                    fs.Write(info, 0, info.Length);

    Test Result: 

    Best regards,

    Jack J Jun.

    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

    Monday, December 31, 2018 3:14 AM
  • Monday, December 31, 2018 6:42 AM
  • You dont know to read on english i say download files from ftp WITH OUT THE FOLDER JUST THE EXE OR WHAT EVER IN THE FOLDER FTP SERVER....
    Monday, December 31, 2018 12:50 PM
  • You can replace FileStream to Memory stream. .NET reference to MemoryStream is in my post above. File download is created by same way as FileStream using.
    Monday, December 31, 2018 3:58 PM
  • We know how to read English.  The problem is you don't know how to ask questions.  Your comment "without the folder" doesn't make any sense at all.  Are you saying you want to fetch files from an FTP server inside your program, without using a separate application?  The folks here have answered that question.  Are you saying you want to fetch a file from an FTP server but you don't know what folder it's in?  That can be done, too, by listing the contents of the FTP server's directory.

    If that's not what you meant, then you need to provide an example of what you want to do, because it is certainly not clear from your question.  The "folder" concept just doesn't fit.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Wednesday, January 2, 2019 9:21 PM