Archived Forum Post

Index of archived forum posts

Question:

SFTP createDir non-recursive and fails if exists?

May 11 '15 at 12:53

I've been very impressed with how sophisticated this software feels on Objective-C. So I was a little surprised to find the following and wanted to make sure I wasn't using it incorrectly:

  1. SFTP's createDir function doesn't work recursively.
  2. Attempting to create a directory that already exists results in a failure.

** I see that sftp itself lacks these abilities. So I wrote a method that splits the directory path into components and then loops while creating deeper directories. If it tries to create an already-created directory and fail's I'm going to have to ignore that failure. I'm troubled by ignoring those failures.

Best practice to recursively create directories while gracefully dealing with failures?


Answer

Yes, the SFTP createDir does not work recursively. Your program would need to explicitly split the path into components and create each separately.

For the "directory already exists" failure: If it is easy to diagnose that the failure is for this reason, then I think it's best to let it fail and leave it to the application as to whether it should be ignored or not.