How to check whether a remoting file exists? - WeOnlyDo Discussion board

How to check whether a remoting file exists? (General questions)

by rogerrong, Tuesday, November 10, 2009, 23:43 (5490 days ago)

We are using the wodSFTP.NET 3.3.7 in a C# application.

We need to find a way to identify whether a file exist in a particular directory on the remoting server. We searched the question history regarding this question and noticed that there is not a simple function returning a true/false value for it. The workaround could be using the SFTP.RealPath( MyFilePathHere ) or SFTP.ListDir( MyFileDirectoryHere ) and rely on the events to get the result.

We would like to know, which is the better way? Sample code would be appreciated.

By the way, we are using the SFTP in the block mode.

Thanks.


Re: How to check whether a remoting file exists?

by wodDamir, Tuesday, November 10, 2009, 23:49 (5490 days ago) @ rogerrong

Hi Roger,

Since you're using Blocking mode, I would suggest using RealPath method in a try...catch block.

This way the component will return an error if file doesn't exist.

Can you try that?

regards,
Damba

Re: How to check whether a remoting file exists?

by rogerrong, Wednesday, November 11, 2009, 00:28 (5490 days ago) @ wodDamir

Hi Roger,

Since you're using Blocking mode, I would suggest using RealPath method in a try...catch block.

This way the component will return an error if file doesn't exist.

Can you try that?

regards,
Damba

Thanks, it works perfectly! [:smile:]