Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7277977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:48:47+00:00 2026-05-28T22:48:47+00:00

Here is the Solution ,thanks Gustavo for the suggestion: class Program { static void

  • 0

Here is the Solution ,thanks Gustavo for the suggestion:

class Program
{
    static void Main(string[] args)
    {
        ConsoleApplication1.Program test = new Program();
        string Name = "SE_TEST";
        string[] filteredfiles = test.GetFileList();
        string[] files = filteredfiles;
    foreach (string file in files)
    {

        bool b;
        if (b = file.Contains(Name))
        {
            test.Download(file);

        }
    }
    }
    public string[] GetFileList()
    {
        string[] downloadFiles;
        StringBuilder result = new StringBuilder();
        WebResponse response = null;
        StreamReader reader = null;
        try
        {
            FtpWebRequest reqFTP;
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + "1.0.0.1" + "/"));
            reqFTP.UseBinary = true;
            reqFTP.Credentials = new NetworkCredential("sh", "SE");
            reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
            reqFTP.Proxy = null;
            reqFTP.KeepAlive = false;
            reqFTP.UsePassive = false;
            response = reqFTP.GetResponse();
            reader = new StreamReader(response.GetResponseStream());
            string line = reader.ReadLine();
            while (line != null)
            {
                result.Append(line);
                result.Append("\n");
                line = reader.ReadLine();
            }
            // to remove the trailing '\n'
            result.Remove(result.ToString().LastIndexOf('\n'), 1);
            return result.ToString().Split('\n');
        }
        catch (Exception ex)
        {
            if (reader != null)
            {
                reader.Close();
            }
            if (response != null)
            {
                response.Close();
            }                
            downloadFiles = null;
            return downloadFiles;
        }
    }

    private void Download(string file)
    {                       

        try
        {
            FtpWebRequest reqFTP;
            string ftpserverIp = "1.0.0.1";

            string fileName = @"c:\downloadDir\" + file;
            FileInfo downloadFile = new FileInfo(fileName);
            // string uri = "ftp://1.0.0.1";
             FileStream outputStream = new FileStream(fileName, FileMode.Append);
             reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpserverIp + "/" + file));
            reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
            reqFTP.UseBinary = true;
            reqFTP.KeepAlive = false;
            reqFTP.Timeout = -1;
            reqFTP.UsePassive = true;
            reqFTP.Credentials = new NetworkCredential("sh", "SE");
            FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
            Stream ftpStream = response.GetResponseStream();
            long cl = response.ContentLength;
           // reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
            int bufferSize = 4096;
            int readCount;
            byte[] buffer = new byte[bufferSize];
            readCount = ftpStream.Read(buffer, 0, bufferSize);
            Console.WriteLine("Connected: Downloading File");
            while (readCount > 0)
            {
                outputStream.Write(buffer, 0, readCount);
                readCount = ftpStream.Read(buffer, 0, bufferSize);
                Console.WriteLine(readCount.ToString());
            }

            ftpStream.Close();
            outputStream.Close();
            response.Close();
            Console.WriteLine("Downloading Complete");
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }

    }
    }
}

It works as expected but not sure about the performance,is this any better way to do please suggest.Anyway thanks for your suggestion

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:48:47+00:00Added an answer on May 28, 2026 at 10:48 pm
    • List all files with the method:
      WebRequestMethods.Ftp.ListDirectoryDetails

    • Filter FileNames with Contains()

    • Download ALL the Files that Contains your string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SOLUTION Thanks to casperOne's answer , here is my resulting function: Shared Function FormatDate(ByVal
the solution here: Jeditable CANCEL callback from AJAX callback? using onreset() doesnt seem to
I'm searching for the cleanest solution here. I would like to code a stored
Just looking for the first step basic solution here that keeps the honest people
gem install heroku failed with following message and I have tried the solution here
I'm just wondering what the optimal solution is here. Say I have a normalized
I am trying to use the solution given here -> C# ADO.NET: nulls and
I am aware that there is a similar question here with no solution. I'm
Here is my ideal solution: a free tool that reads a .csporj or .sln
Here is how our current php development solution is set up: Each developer work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.