SFTP and LoopFiles (wodFtpDLX / wodFtpDLX.NET)
Hello
I am trying to get an example for getting a count of files in a directory along with the file names before i download using SFTP Dll.
Any help will be appreciated.
Thanks,
Premal
Hello
I am trying to get an example for getting a count of files in a directory along with the file names before i download using SFTP Dll.
Any help will be appreciated.
Thanks,
Premal
by wodDamir , (6025 days ago) @ Premal
Hi Premal,
We are talking about wodFtpDLX, right?
If so, you can check DirItems collection for Count property after ListDir is executed.
Can you try that?
Regards,
Damba
by Premal, (6025 days ago) @ wodDamir
Hello DambaI am using wodSFTP.NET. I would like to get an example of how to find out number of files exists in a folder on my SFTP server along with their fielnames and then download all of them.
Thanks,
PremalHi Premal,
We are talking about wodFtpDLX, right?
If so, you can check DirItems collection for Count property after ListDir is executed.
Can you try that?
Regards,
Damba
by wodDamir , (6025 days ago) @ Premal
Premal,
In that case, all you need to do is Call ListAttributes method on the directory, and check Args.Length parameter in AttributesData Event.
Can you try that?
Regards,
Damba
by Premal, (6024 days ago) @ wodDamir
Hello Damba
I really appreciate for the prompt feedback. Can you please provide me with an example of how to use ListAttrbutes using events in C#?
Thanks,
Premal
Premal,
In that case, all you need to do is Call ListAttributes method on the directory, and check Args.Length parameter in AttributesData Event.
Can you try that?
Regards,
Damba
by wodDamir , (6024 days ago) @ Premal
Premal,
All you need to do is this:
[code]sftp1.ListAttributes( /your/path );[/code]
And do this in AttributesData Event:
[code]void sftp1_AttributesDataEvent(object Sender, WeOnlyDo.Client.SFTP.AttributesArgs[] Args)
{
Console.WriteLine(Args.Length.ToString());
}[/code]
That's all the code you need, besides the connecting part. Can you please try that?
Regards,
Damba
by premal, (6024 days ago) @ wodDamir
Hello Damba
That works perfectly. Thanks for all your help. Also is it better to download all the files at once from a given folder on SFTP server using GetFile(string LocalPath, string RemoteFile) or should we get the names of each file and then download one by one. I guess downloading one by one may be a hit on the connectiosn to SFTP but if we downlaod all the files at once using GetFile(string LocalPath, string RemoteFile), can I verify number of files downloaded?
Thanks,
Premal
Premal,
All you need to do is this:
[code]sftp1.ListAttributes( /your/path );[/code]
And do this in AttributesData Event:
[code]void sftp1_AttributesDataEvent(object Sender, WeOnlyDo.Client.SFTP.AttributesArgs[] Args)
{
Console.WriteLine(Args.Length.ToString());
}[/code]That's all the code you need, besides the connecting part. Can you please try that?
Regards,
Damba
by wodDamir , (6024 days ago) @ premal
Premal,
It completely depends on your approach. Both ways will work. You can't know how many files were downloaded, but you can always make a member variable (i.e. FilesCount) and increase it by one on each LoopItem event.
That way you get total number of files downloaded.
Hope this helps.
Regards,
Damba
by Premal, (6024 days ago) @ wodDamir
Hello Damba
Perfect. That works great! Thanks for all your help!
Thanks,
Premal
Premal,
It completely depends on your approach. Both ways will work. You can't know how many files were downloaded, but you can always make a member variable (i.e. FilesCount) and increase it by one on each LoopItem event.
That way you get total number of files downloaded.
Hope this helps.
Regards,
Damba
by Premal, (6024 days ago) @ Premal
Hello Damba
It all works well if I use it with events. I would like to get the same functionality without using events....that is setting Blocking = true. How would i be able to get FileCount as well as FileNames for the files I want to download from SFTP server?
Thanks,
Premal
Hello Damba
Perfect. That works great! Thanks for all your help!
Thanks,
PremalPremal,
It completely depends on your approach. Both ways will work. You can't know how many files were downloaded, but you can always make a member variable (i.e. FilesCount) and increase it by one on each LoopItem event.
That way you get total number of files downloaded.
Hope this helps.
Regards,
Damba
by woddrazen , (6024 days ago) @ Premal
Premal,
You should at least use AttributesData Event to populate collection of file size. Without Events this will not work. Only if you want to parse file size from ListItem Property by yourself. ListItem Property is populated when you execute ListDir Method.
Here is example for collection:
http://www.weonlydo.com/index.asp?forum=1&action=view&topic=1087331420#1087331420
Other option is to switch to our other component wodFtpDLX.NET. wodFtpDLX.NET supports FTP, FTPS and SFTP protocol. Usage is much same as in wodSFTP.NET.
wodFtpDLX.NET supports DirItems collections which can be used outside of Events to parse directory structure. In your case file size.
[code] dlx1 = new WeOnlyDo.Client.FtpDLX();
dlx1.Hostname = hostname ;
dlx1.Protocol = WeOnlyDo.Client.Protocols.SFTP;
dlx1.Blocking = true;
dlx1.Login = login ;
dlx1.Password = password ;
dlx1.Connect();
dlx1.ListDir( /home/something );
foreach (WeOnlyDo.Client.DirItem Item in dlx1.DirItems)
{
Console.WriteLine(Item.Name + - + Item.Size);
}
Console.WriteLine(dlx1.DirItems.Count); //items count[/code]
Price diffrence between wodSFTP.NET and wodFtpDLX.NET is 20$.
Drazen
by Premal, (6023 days ago) @ woddrazen
Thanks a lot. That was great advice. I will download wodFtpDLX.NET and see how that works. Thanks again for all your help.
Thanks,
Premal
Premal,
You should at least use AttributesData Event to populate collection of file size. Without Events this will not work. Only if you want to parse file size from ListItem Property by yourself. ListItem Property is populated when you execute ListDir Method.Here is example for collection:
http://www.weonlydo.com/index.asp?forum=1&action=view&topic=1087331420#1087331420Other option is to switch to our other component wodFtpDLX.NET. wodFtpDLX.NET supports FTP, FTPS and SFTP protocol. Usage is much same as in wodSFTP.NET.
wodFtpDLX.NET supports DirItems collections which can be used outside of Events to parse directory structure. In your case file size.
[code] dlx1 = new WeOnlyDo.Client.FtpDLX();dlx1.Hostname = hostname ;
dlx1.Protocol = WeOnlyDo.Client.Protocols.SFTP;
dlx1.Blocking = true;
dlx1.Login = login ;
dlx1.Password = password ;
dlx1.Connect();dlx1.ListDir( /home/something );
foreach (WeOnlyDo.Client.DirItem Item in dlx1.DirItems)
{
Console.WriteLine(Item.Name + - + Item.Size);
}Console.WriteLine(dlx1.DirItems.Count); //items count[/code]
Price diffrence between wodSFTP.NET and wodFtpDLX.NET is 20$.
Drazen
I've heard that you are amazing with your replies coming back so quickly - and now I've seen the speed in which you reply first hand.
Your support is fantastic.
Thank you very much for the rapid responses. I was a little nervous about dealing with a company that is on a different continent from me. You have proven my concerns to be unfounded.
...not only that you provide these components at very reasonable cost, your responsiveness to emailed technical questions is simply outstanding...
I would highly recommend this to anyone who needs a good quality SFTP solution.
Thank you so much for your hard work and commitment in producing well thought-out solutions. WeOnlyDo is very committed to customer satisfaction!
I can only hope I will have the pleasure to work with other products by "We Only Do" in the future.
It is very refreshing to find such helpful, knowledgeable and quick responding technical support.
May I say how nice it is to work with components so complete and self-explanatory that using them in my application is as instinctive as though I wrote them myself?
It is very refreshing to find such helpful, knowledgeable and quick responding technical support.