diff --git a/DearFTP/Connection/Commands/StoreCommand.cs b/DearFTP/Connection/Commands/StoreCommand.cs index 772be37..e7a7a9f 100644 --- a/DearFTP/Connection/Commands/StoreCommand.cs +++ b/DearFTP/Connection/Commands/StoreCommand.cs @@ -13,7 +13,9 @@ namespace DearFTP.Connection.Commands public string[] Aliases { get; } = new string[] { - "STOR" + "APPE", + "STOR", + "STOU" }; public void Execute(Session session, FtpStream stream, string alias, string argument) @@ -26,7 +28,9 @@ namespace DearFTP.Connection.Commands return; } - var (navigablePath, realPath) = session.NavigablePath.GetNewSystemFilePath(argument); + string path = alias.ToUpper() == "STOU" ? Path.GetRandomFileName() : argument; + + var (navigablePath, realPath) = session.NavigablePath.GetNewSystemFilePath(path); if (realPath == null) { @@ -48,16 +52,16 @@ namespace DearFTP.Connection.Commands stream.Send(ResponseCode.FileStatusOK, "Waiting file."); - ReceiveFile(dataConnection.Stream, realPath); + ReceiveFile(dataConnection.Stream, realPath, alias.ToUpper() == "APPE"); dataConnection.Close(); stream.Send(ResponseCode.CloseDataConnection, "File received."); } - private void ReceiveFile(NetworkStream stream, string path) + private void ReceiveFile(NetworkStream stream, string path, bool append) { - using (var file = File.Open(path, FileMode.Create)) + using (var file = File.Open(path, append ? FileMode.Append : FileMode.Create)) { Span buffer = stackalloc byte[BufferSize]; int readBytes;