static int SFTP_ServerRecvInit(WOLFSSH* ssh) {
    int  len;
    byte id;
    word32 sz = 0;
    word32 version = 0;
    byte buf[LENGTH_SZ + MSG_ID_SZ + UINT32_SZ];

    if ((len = wolfSSH_stream_read(ssh, buf, sizeof(buf))) != sizeof(buf)) {
        return len;
    }

    if (SFTP_GetSz(buf, &sz,
                MSG_ID_SZ + UINT32_SZ, WOLFSSH_MAX_SFTP_RECV) != WS_SUCCESS) {
        wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL);
        return WS_BUFFER_E;
    }

    /* compare versions supported */
    id = buf[LENGTH_SZ];
    if (id != WOLFSSH_FTP_INIT) {
        WLOG(WS_LOG_SFTP, "Unexpected SFTP type received");
        wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL);
        return WS_BUFFER_E;
    }

    ato32(buf + LENGTH_SZ + MSG_ID_SZ, &version);
    if (version != WOLFSSH_SFTP_VERSION) {
        WLOG(WS_LOG_SFTP, "Unsupported SFTP version, sending version 3");
    }

    /* silently ignore extensions if not supported */
    sz = sz - MSG_ID_SZ - UINT32_SZ;
    if (sz > 0) {
        byte* data = (byte*)WMALLOC(sz, NULL, DYNTYPE_BUFFER);
        if (data ==  NULL) return WS_MEMORY_E;
        len = wolfSSH_stream_read(ssh, data, sz);
        WFREE(data, NULL, DYNTYPE_BUFFER);
        if (len != (int)sz)
            return len;
    }

    ssh->reqId++;
    return WS_SUCCESS;
}
static int SFTP_ServerRecvInit(WOLFSSH* ssh) {
    int  len;
    byte id;
    word32 sz = 0;
    word32 version = 0;
    byte buf[LENGTH_SZ + MSG_ID_SZ + UINT32_SZ];

    if ((len = wolfSSH_stream_read(ssh, buf, sizeof(buf))) != sizeof(buf)) {
        return len;
    }

    if (SFTP_GetSz(buf, &sz,
                MSG_ID_SZ + UINT32_SZ, WOLFSSH_MAX_SFTP_RECV) != WS_SUCCESS) {
        wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL);
        return WS_BUFFER_E;
    }

     
    id = buf[LENGTH_SZ];
    if (id != WOLFSSH_FTP_INIT) {
        WLOG(WS_LOG_SFTP, "Unexpected SFTP type received");
        wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL);
        return WS_BUFFER_E;
    }

    ato32(buf + LENGTH_SZ + MSG_ID_SZ, &version);
    if (version != WOLFSSH_SFTP_VERSION) {
        WLOG(WS_LOG_SFTP, "Unsupported SFTP version, sending version 3");
    }

     
    sz = sz - MSG_ID_SZ - UINT32_SZ;
    if (sz > 0) {
        byte* data = (byte*)WMALLOC(sz, NULL, DYNTYPE_BUFFER);
        if (data ==  NULL) return WS_MEMORY_E;
        len = wolfSSH_stream_read(ssh, data, sz);
        WFREE(data, NULL, DYNTYPE_BUFFER);
        if (len != (int)sz)
            return len;
    }

    ssh->reqId++;
    return WS_SUCCESS;
}