List folders using FTP

To list all files and folders in a specific FTP folder just us ChangeFolder and GetList methods:

// C# version

using (Ftp client = new Ftp())
{
    client.Connect("ftp.example.org");
    client.Login("user", "password");

    client.ChangeFolder("reports");

    List<FtpItem> items = client.GetList();

    foreach (FtpItem item in items)
    {
        Console.WriteLine("Name:        {0}", item.Name);
        Console.WriteLine("Size:        {0}", item.Size);
        Console.WriteLine("Modify date: {0}", item.ModifyDate);

        Console.WriteLine("Is folder:   {0}", item.IsFolder);
        Console.WriteLine("Is file:     {0}", item.IsFile);
        Console.WriteLine("Is symlink:  {0}", item.IsSymlink);

        Console.WriteLine();
    }

    client.Close();
}
' VB.NET version

Using client As New Ftp()
	client.Connect("ftp.example.org")
	client.Login("user", "password")

	client.ChangeFolder("reports")

	Dim items As List(Of FtpItem) = client.GetList()

	For Each item As FtpItem In items
		Console.WriteLine("Name:        {0}", item.Name)
		Console.WriteLine("Size:        {0}", item.Size)
		Console.WriteLine("Modify date: {0}", item.ModifyDate)

		Console.WriteLine("Is folder:   {0}", item.IsFolder)
		Console.WriteLine("Is file:     {0}", item.IsFile)
		Console.WriteLine("Is symlink:  {0}", item.IsSymlink)

		Console.WriteLine()
	Next

	client.Close()
End Using

You can download Ftp.dll .NET FTP and FTPS library.

Tags:    

Questions?

Consider using our Q&A forum for asking questions.

6 Responses to “List folders using FTP”

  1. Ivan Lemos Says:

    Hi.. My name is Ivan and I from Brazil

    Thank you for Ftp component !! =)

    My I have one question.

    How i make for get the progress file upload in percent

    Thanks

  2. Limilabs support Says:

    @Ivan,

    You just need to subscribe to Ftp Progress event:

    client.Progress += (sender, args) =>
        {
            var transfered = args.Percentage;
            client.Abort();
        };
    
  3. Ivan Lemos Says:

    How do I make in in VB.NET?

  4. Ivan Lemos Says:

    Hi Guys!

    This is my solution:

    AddHandler client.Progress, Sub(sender As Object, args As ProgressEventArgs)
        Me.ProgressBar.Value = args.Percentage
    End Sub
    

    Thanks

  5. Drew Says:

    How do you ignore the “.” and “..” directories?

  6. Limilabs support Says:

    @Drew,

    By name.