SFTP and LoopFiles - WeOnlyDo Discussion board

SFTP and LoopFiles (wodFtpDLX / wodFtpDLX.NET)

by Premal, Tuesday, March 03, 2009, 20:53 (5504 days ago)

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

Re: SFTP and LoopFiles

by wodDamir, Tuesday, March 03, 2009, 21:08 (5504 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

Re: SFTP and LoopFiles

by Premal, Tuesday, March 03, 2009, 21:14 (5504 days ago) @ wodDamir


Hello Damba

I 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,
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

Re: SFTP and LoopFiles

by wodDamir, Tuesday, March 03, 2009, 21:31 (5504 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

Re: SFTP and LoopFiles

by Premal, Wednesday, March 04, 2009, 13:22 (5503 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

Re: SFTP and LoopFiles

by wodDamir, Wednesday, March 04, 2009, 13:25 (5503 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

Re: SFTP and LoopFiles

by premal, Wednesday, March 04, 2009, 15:09 (5503 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

Re: SFTP and LoopFiles

by wodDamir, Wednesday, March 04, 2009, 15:18 (5503 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

Re: SFTP and LoopFiles

by Premal, Wednesday, March 04, 2009, 15:26 (5503 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

Re: SFTP and LoopFiles

by Premal, Wednesday, March 04, 2009, 21:20 (5503 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,
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

Re: SFTP and LoopFiles

by woddrazen, Wednesday, March 04, 2009, 23:17 (5503 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

Re: SFTP and LoopFiles

by Premal, Thursday, March 05, 2009, 15:01 (5502 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#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