Add APPE and STOU command
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user