diff --git a/packages/backend/src/websocket/handlers/sftp.handler.ts b/packages/backend/src/websocket/handlers/sftp.handler.ts index cfd8bb7..6025d0a 100644 --- a/packages/backend/src/websocket/handlers/sftp.handler.ts +++ b/packages/backend/src/websocket/handlers/sftp.handler.ts @@ -46,7 +46,9 @@ export async function handleSftpOperation( const fileContent = payload?.content ?? payload?.data ?? ''; const encoding = payload?.encoding; if (payload?.path) { - const dataToSend = (typeof fileContent === 'string') ? fileContent : ''; + let dataToSend = (typeof fileContent === 'string') ? fileContent : ''; + // Convert only true line endings (CRLF and standalone CR not followed by LF) to LF to ensure Unix-compatible line endings + dataToSend = dataToSend.replace(/\r\n/g, '\n').replace(/\r(?!\n)/g, '\n'); sftpService.writefile(sessionId, payload.path, dataToSend, requestId, encoding); } else throw new Error("Missing 'path' in payload for writefile"); break;