From aaf4c056304696712d2596fa03ea14a8cd3a9f00 Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Sun, 11 Feb 2024 16:38:28 +0100 Subject: [PATCH] Fixed moving items to the location they are currently at --- .../Features/Servers/Helpers/ServerFtpFileAccess.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Moonlight/Features/Servers/Helpers/ServerFtpFileAccess.cs b/Moonlight/Features/Servers/Helpers/ServerFtpFileAccess.cs index 549570a..bd6bdf8 100644 --- a/Moonlight/Features/Servers/Helpers/ServerFtpFileAccess.cs +++ b/Moonlight/Features/Servers/Helpers/ServerFtpFileAccess.cs @@ -1,6 +1,7 @@ using System.Net; using System.Text; using FluentFTP; +using MoonCore.Helpers; using Moonlight.Features.FileManager.Models.Abstractions.FileAccess; namespace Moonlight.Features.Servers.Helpers; @@ -94,12 +95,18 @@ public class ServerFtpFileAccess : IFileAccess { var fromEntry = Client.GetObjectInfo(from); + var dest = to + Path.GetFileName(from); + var fromWithSlash = from.StartsWith("/") ? from : "/" + from; + + if (fromWithSlash == dest) + return Task.CompletedTask; + if (fromEntry.Type == FtpObjectType.Directory) // We need to add the folder name here, because some ftp servers would refuse to move the folder if its missing - Client.MoveDirectory(from, to + Path.GetFileName(from)); + Client.MoveDirectory(from, dest); else // We need to add the file name here, because some ftp servers would refuse to move the file if its missing - Client.MoveFile(from, to + Path.GetFileName(from)); + Client.MoveFile(from, dest); return Task.CompletedTask; });