title: Java jsch.ChannelSftp - How to know if mkdir failed due to a directory alread existing
body: <p>I'm using <code>com.jcraft.jsch.ChannelSftp</code> as my SFTP client.</p>
  
  <p>I would like to attempt to create a directory, and if this fails because the directory already exists, continue on as if nothing happened. If this fails because of some other reason, for example a network error, I want to stop execution of the program.</p>
  
  <pre><code>import com.jcraft.jsch.ChannelSftp;
  import com.jcraft.jsch.SftpException;
  
  ChannelSftp sftpClient;
  //...
  try {
      sftpClient.mkdir("test")
  } catch (SftpException e) {
      System.out.println(e.id); // Prints "Failure"
      System.out.println(e.getMessage()); // Prints "null"
      assert (e.id == ChannelSftp.SSH_FX_FAILURE);
      assert (e.id == 4);
  }
  </code></pre>
  
  <p>The ID for this failure is <code>4</code>.</p>
  
  <p>I noticed that if I <code>mkdir</code> inside a directory where I don't have permissions, the exception's id will be <code>3</code>/<code>SSH_FX_PERMISSION_DENIED</code>.</p>
  
  <p>How can I determine if the <code>mkdir</code> failed because the directory was already created?</p>
  
  <p>Is it safe to assume that if the id is 4, then the failure was due to the folder already existing?</p>