Add APPE and STOU command

This commit is contained in:
2019-07-18 13:18:15 +02:00
parent a2f867480a
commit 8c2b32d6b1

View File

@@ -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<byte> buffer = stackalloc byte[BufferSize];
int readBytes;