diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index f4d2d49..c00eedf 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -993,20 +993,8 @@ static THREAD_RETURN WOLFSSH_THREAD server_worker(void* vArgs) switch (ret) { case WS_SCP_COMPLETE: - { - byte buf[1]; - printf("scp file transfer completed\n"); - if (wolfSSH_stream_exit(threadCtx->ssh, 0) != WS_SUCCESS) { - fprintf(stderr, "Error with SSH stream exit.\n"); - } - /* Peer MUST send back a SSH_MSG_CHANNEL_CLOSE unless already - * sent*/ - ret = wolfSSH_stream_read(threadCtx->ssh, buf, 1); - if (ret != WS_EOF) { - fprintf(stderr, "Was expecting EOF\n"); - } - ret = 0; - } + printf("scp file transfer completed\n"); + ret = 0; break; case WS_SFTP_COMPLETE: diff --git a/src/wolfscp.c b/src/wolfscp.c index b972eec..02b9a2f 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -619,6 +619,11 @@ int DoScpSource(WOLFSSH* ssh) } /* end while */ + if (ret == WS_SUCCESS && ssh->scpState == SCP_DONE) { + /* Send SSH_MSG_CHANNEL_CLOSE */ + ret = wolfSSH_stream_exit(ssh, 0); + } + return ret; } @@ -678,6 +683,20 @@ int DoScpRequest(WOLFSSH* ssh) } } + if (ret == WS_SUCCESS && ssh->scpState == SCP_DONE) { + byte buf[1]; + + /* Peer MUST send back a SSH_MSG_CHANNEL_CLOSE unless already + sent*/ + ret = wolfSSH_stream_read(ssh, buf, 1); + if (ret != WS_EOF) { + WLOG(WS_LOG_DEBUG, scpState, "Did not receive EOF packet"); + } + else { + ret = WS_SUCCESS; + } + } + return ret; }