code: private void makeDirectories(String dirPath, String permissions) throws IOException {
          if (!dirPath.contains("/")) return;
  
          String[] pathElements = dirPath.split("/");
  
          if (pathElements.length == 1) return;
  
          // if the string ends with / it means that the dir path contains only directories,
          // otherwise if it does not contain /, the last element of the path is the file name,
          // so it must be ignored when creating the directory structure
          int lastElement = dirPath.endsWith("/") ? pathElements.length : pathElements.length - 1;
  
          for (int i = 0; i < lastElement; i++) {
              String singleDir = pathElements[i];
              if (singleDir.isEmpty()) continue;
  
              if (!ftpClient.changeWorkingDirectory(singleDir)) {
                  if (ftpClient.makeDirectory(singleDir)) {
                      Logger.debug(LOG_TAG, "Created remote directory: " + singleDir);
                      if (permissions != null) {
                          setPermission(singleDir, permissions);
                      }
                      ftpClient.changeWorkingDirectory(singleDir);
                  } else {
                      throw new IOException("Unable to create remote directory: " + singleDir);
                  }
              }
          }
      }
docs: Creates a nested directory structure on a FTP server and enters into it.
  @param dirPath Path of the directory, i.e /projects/java/ftp/demo
  @param permissions UNIX permissions to apply to created directories. If null, the FTP
  server defaults will be applied, because no UNIX permissions will be
  explicitly set
  @throws IOException if any error occurred during client-server communication