From 9007aa8ca126ded124950f530926e7819a8dfa81 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Sun, 5 Dec 2021 18:42:36 -0800
Subject: [PATCH] Fix FTPS upload failure: !DATA ERROR 0 receiving on data
 socket

Don't treat CRYPT_ERROR_COMPLETE (-24) as a socket error during upload since it's an indication that the remote closed the connection and is the normal "end of file/transfer" indicator, not an error. 'rd' is already 0 in this case, so no need to set at all (since recv() returns 0 upon disconnect and that's what we're emulating here).

Fixes issue #309 reported by Jas Hud.
---
 src/sbbs3/ftpsrvr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/sbbs3/ftpsrvr.c b/src/sbbs3/ftpsrvr.c
index 6efe52394f..c1e41333b7 100644
--- a/src/sbbs3/ftpsrvr.c
+++ b/src/sbbs3/ftpsrvr.c
@@ -978,7 +978,8 @@ static void receive_thread(void* arg)
 			int status = cryptPopData(*xfer.data_sess, buf, sizeof(buf), &rd);
 			if (status != CRYPT_OK) {
 				GCES(status, *xfer.data_sock, *xfer.data_sess, estr, "popping data");
-				rd = -1;
+				if (status != CRYPT_ERROR_COMPLETE)
+					rd = SOCKET_ERROR;
 			}
 		}
 		else {
-- 
GitLab