diff --git a/ShareX.HelpersLib/Helpers/Helpers.cs b/ShareX.HelpersLib/Helpers/Helpers.cs index 0f530c905..29ad0c794 100644 --- a/ShareX.HelpersLib/Helpers/Helpers.cs +++ b/ShareX.HelpersLib/Helpers/Helpers.cs @@ -43,6 +43,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; +using System.Web; namespace ShareX.HelpersLib { @@ -215,7 +216,7 @@ public static string GetValidFilePath(string filePath) public static string GetValidURL(string url, bool replaceSpace = false) { if (replaceSpace) url = url.Replace(' ', '_'); - return new string(url.Where(c => ValidURLCharacters.Contains(c)).ToArray()); + return HttpUtility.UrlPathEncode(url); } public static string GetXMLValue(string input, string tag) diff --git a/ShareX.UploadersLib/FileUploaders/FTP.cs b/ShareX.UploadersLib/FileUploaders/FTP.cs index 32035134f..c656763ed 100644 --- a/ShareX.UploadersLib/FileUploaders/FTP.cs +++ b/ShareX.UploadersLib/FileUploaders/FTP.cs @@ -110,7 +110,7 @@ public override UploadResult Upload(Stream stream, string fileName) UploadResult result = new UploadResult(); fileName = Helpers.GetValidURL(fileName); - string subFolderPath = Account.GetSubFolderPath(); + string subFolderPath = Account.GetSubFolderPath(null, NameParserType.FolderPath); string path = subFolderPath.CombineURL(fileName); bool uploadResult; diff --git a/ShareX.UploadersLib/FileUploaders/FTP/FTPAccount.cs b/ShareX.UploadersLib/FileUploaders/FTP/FTPAccount.cs index f3b03efe6..b5838d7bd 100644 --- a/ShareX.UploadersLib/FileUploaders/FTP/FTPAccount.cs +++ b/ShareX.UploadersLib/FileUploaders/FTP/FTPAccount.cs @@ -138,9 +138,9 @@ public FTPAccount() FTPSCertificateLocation = string.Empty; } - public string GetSubFolderPath(string filename = null) + public string GetSubFolderPath(string filename = null, NameParserType nameParserType = NameParserType.URL) { - string path = NameParser.Parse(NameParserType.URL, SubFolderPath.Replace("%host", Host)); + string path = NameParser.Parse(nameParserType, SubFolderPath.Replace("%host", Host)); return URLHelpers.CombineURL(path, filename); } @@ -175,8 +175,6 @@ public string GetUriPath(string filename, string subFolderPath = null) subFolderPath = GetSubFolderPath(); } - subFolderPath = URLHelpers.URLPathEncode(subFolderPath); - UriBuilder httpHomeUri; var httpHomePath = GetHttpHomePath(); @@ -242,7 +240,7 @@ public string GetFtpPath(string filemame) return string.Empty; } - return URLHelpers.CombineURL(FTPAddress, GetSubFolderPath(filemame)); + return URLHelpers.CombineURL(FTPAddress, GetSubFolderPath(filemame, NameParserType.FolderPath)); } public override string ToString()