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
June 28th, 2017 at 17:12
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
June 28th, 2017 at 19:02
@Ivan,
You just need to subscribe to Ftp Progress event:
client.Progress += (sender, args) => { var transfered = args.Percentage; client.Abort(); };July 1st, 2017 at 17:25
How do I make in in VB.NET?
July 1st, 2017 at 19:31
Hi Guys!
This is my solution:
AddHandler client.Progress, Sub(sender As Object, args As ProgressEventArgs) Me.ProgressBar.Value = args.Percentage End SubThanks
March 4th, 2018 at 04:51
How do you ignore the “.” and “..” directories?
March 4th, 2018 at 13:07
@Drew,
By name.