0

I need to verify that a unix folder exists, from my C# application using SharpSsh.
I thought of trying this:

SshExec.RunCommand("-d " + folder)

But the result is always '2' regardless if the folder is there or not. I could implement something using:

Sftp.GetFileList(folder)

But prefer not to because this folder may contain numerous files and It causes a delay while all of them are retrieved which is not elegant.

Any ideas?

Edit: I tried this:

string folder = "/foldername";
string result = sshExec.RunCommand("[ -d " + folder + "] && echo 'true' || echo 'false'");

if (result == "false") 
throw new Exception("Directory " + foldername+ " + is not found.");

String 'result' is set as "false\n" even though the directory exists. If I skip the check I can work with the directory without problems.

Yoav
  • 2,077
  • 6
  • 27
  • 48

1 Answers1

2

Use

SshExec.RunCommand("ls -la " + folder)

or

SshExec.RunCommand("ls " + folder)

if your folder is not hidden and you dont need size information

Cheap command that will fill your output string with permissions and folder info if exists

Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82