diff --git a/src/blua/liolib.c b/src/blua/liolib.c
index 2ccfa70e86e39ae013420d5bdad2ebf8c6ac3e80..a055aad3f600a4482502da148467bfe622751fe3 100644
--- a/src/blua/liolib.c
+++ b/src/blua/liolib.c
@@ -321,6 +321,12 @@ void Got_LuaFile(UINT8 **cp, INT32 playernum)
 
 	RemoveLuaFileTransfer();
 
+	if (waitingforluafilecommand)
+	{
+		waitingforluafilecommand = false;
+		CL_PrepareDownloadLuaFile();
+	}
+
 	if (server && luafiletransfers)
 		SV_PrepareSendLuaFile();
 }
diff --git a/src/d_clisrv.c b/src/d_clisrv.c
index 275eb790e8072246b3c5f81707f153768dafd5cb..dbf10d58e43f18d93710ed54094f8798b8f390f8 100644
--- a/src/d_clisrv.c
+++ b/src/d_clisrv.c
@@ -3256,6 +3256,7 @@ void D_QuitNetGame(void)
 	CloseNetFile();
 	RemoveAllLuaFileTransfers();
 	waitingforluafiletransfer = false;
+	waitingforluafilecommand = false;
 
 	if (server)
 	{
diff --git a/src/d_netfil.c b/src/d_netfil.c
index da190bc5c6085d38ba3a7a845d2fa08ebbbbc23d..c5f3d8658d6fd54a698ce01551ee1a7b2dc902ba 100644
--- a/src/d_netfil.c
+++ b/src/d_netfil.c
@@ -110,6 +110,7 @@ INT32 lastfilenum = -1;
 
 luafiletransfer_t *luafiletransfers = NULL;
 boolean waitingforluafiletransfer = false;
+boolean waitingforluafilecommand = false;
 char luafiledir[256 + 16] = "luafiles";
 
 
@@ -536,6 +537,8 @@ void AddLuaFileTransfer(const char *filename, const char *mode)
 	// Only if there is no transfer already going on
 	if (server && filetransfer == luafiletransfers)
 		SV_PrepareSendLuaFile();
+	else
+		filetransfer->ongoing = false;
 
 	// Store the callback so it can be called once everyone has the file
 	filetransfer->id = id;
@@ -578,6 +581,8 @@ void SV_PrepareSendLuaFile(void)
 	char *binfilename;
 	INT32 i;
 
+	luafiletransfers->ongoing = true;
+
 	// Set status to "waiting" for everyone
 	for (i = 0; i < MAXNETNODES; i++)
 		luafiletransfers->nodestatus[i] = LFTNS_WAITING;
@@ -660,6 +665,12 @@ void CL_PrepareDownloadLuaFile(void)
 		return;
 	}
 
+	if (luafiletransfers->ongoing)
+	{
+		waitingforluafilecommand = true;
+		return;
+	}
+
 	// Tell the server we are ready to receive the file
 	netbuffer->packettype = PT_ASKLUAFILE;
 	HSendPacket(servernode, true, 0, 0);
@@ -674,6 +685,8 @@ void CL_PrepareDownloadLuaFile(void)
 
 	// Make sure all directories in the file path exist
 	MakePathDirs(fileneeded[0].filename);
+
+	luafiletransfers->ongoing = true;
 }
 
 // Number of files to send
diff --git a/src/d_netfil.h b/src/d_netfil.h
index dce2c929fa00d6b467b2e59908a984f8f85bd8b8..be58f807ffca7dde25e1b370e5987268910873cf 100644
--- a/src/d_netfil.h
+++ b/src/d_netfil.h
@@ -95,12 +95,14 @@ typedef struct luafiletransfer_s
 	char *realfilename;
 	char mode[4]; // rb+/wb+/ab+ + null character
 	INT32 id; // Callback ID
+	boolean ongoing;
 	luafiletransfernodestatus_t nodestatus[MAXNETNODES];
 	struct luafiletransfer_s *next;
 } luafiletransfer_t;
 
 extern luafiletransfer_t *luafiletransfers;
 extern boolean waitingforluafiletransfer;
+extern boolean waitingforluafilecommand;
 extern char luafiledir[256 + 16];
 
 void AddLuaFileTransfer(const char *filename, const char *mode);