def create_file_subdirs(sftpClient, filepath):
    # Getting rid of the filename
    lastSlash = filepath.rindex(u"/")
    finalPath = filepath[:lastSlash]
    dirs = finalPath.split(u"/")

    currentDir = u""
    doStat = True
    try:
        while dirs:
            currentDir += dirs.pop(0) + u"/"
            if doStat:
                try:
                    sftpClient.stat(currentDir)
                # The current dir doesn't exists, so we create it
                except __HOLE__ as ioe:
                    if ioe.errno == 2:
                        sftpClient.mkdir(currentDir)
                        # If a dir was not found, it means all the next
                        # won't exist either. So stop bothering to stat
                        doStat = False
                    else:
                        raise
            else:
                sftpClient.mkdir(currentDir)
    except IOError as ioe:
        raise ServiceError(u"Error while creating subdirs {}: {}"
                           .format(finalPath, ioe))
dataset/ETHPy150Open onitu/onitu/drivers/sftp/onitu_sftp/sftp.py/create_file_subdirs