How does one create directory if only required

0 votes
asked Oct 22, 2016 by philj (140 points)

How does one create a directory only if it required does it follow the .net protocol in that the directory is only created if does not exist.

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Oct 24, 2016 by Lukas Matyska (60,650 points)

You can use the DirectoryExists method to check whether specified directory already exists. So the code can look like this:

if (!client.DirectoryExists(outboundDirectory))

Please note, that if you are using FTP protocol, the DirectoryExists method is not supported on all servers. In the case of such server, you have to call client.CreateDirectory(outboundDirectory) and handle potential exception.

If you are using SFTP protocol, there is no problem in using DirectoryExists method.