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 , (5964 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, (5964 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 , (5964 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, (5963 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 , (5963 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, (5963 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 , (5963 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, (5963 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, (5963 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 , (5963 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, (5962 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
...not only that you provide these components at very reasonable cost, your responsiveness to emailed technical questions is simply outstanding...
You did a great job on wodSSH and wodSSHServer! I got a lot for very little money. Thanks!
I really like these products - they are consistently first rate!
Thank you so much for your hard work and commitment in producing well thought-out solutions. WeOnlyDo is very committed to customer satisfaction!
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?
The SFTP ocx is one of the finest pieces of programming I have seen. It worked out of the box...
Thank you for the great customer service ... I am really impressed with the wodSSH ActiveX control.
The wodCrypt product is great and we appreciate your effort to add support for UNIX Crypt.
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.
Your .NET components allow us to blend .NET technology seamlessly with secure communication, and with excellent technical support.