/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App.Storage/Ftp/FtpHelpers.cs
66 строк
2 KB
Kris Vandermotten
Code Quality: Search for chars instead of single-char strings where possible (#18096)
01 фев 2026, 18:28
Не верифицирован
01 фев 2026, 18:28
6a9f925
Код
Авторство
О чём код?
// Copyright (c) Files Community // Licensed under the MIT License. using Files.Shared.Extensions; using FluentFTP; namespace Files.App.Storage { internal static class FtpHelpers { public static string GetFtpPath(string path) { path = path.Replace('\\', '/'); var schemaIndex = path.IndexOf("://", StringComparison.Ordinal) + 3; var hostIndex = path.IndexOf('/', schemaIndex); return hostIndex == -1 ? "/" : path.Substring(hostIndex); } public static Task EnsureConnectedAsync(this AsyncFtpClient ftpClient, CancellationToken cancellationToken = default) { return ftpClient.IsConnected ? Task.CompletedTask : ftpClient.Connect(cancellationToken); } public static string GetFtpHost(string path) { var authority = GetFtpAuthority(path); var index = authority.IndexOf(':', StringComparison.Ordinal); return index == -1 ? authority : authority.Substring(0, index); } public static ushort GetFtpPort(string path) { var authority = GetFtpAuthority(path); var index = authority.IndexOf(':', StringComparison.Ordinal); if (index != -1) return ushort.Parse(authority.Substring(index + 1)); return path.StartsWith("ftps://", StringComparison.OrdinalIgnoreCase) ? (ushort)990 : (ushort)21; } public static string GetFtpAuthority(string path) { path = path.Replace('\\', '/'); var schemaIndex = path.IndexOf("://", StringComparison.Ordinal) + 3; var hostIndex = path.IndexOf('/', schemaIndex); if (hostIndex == -1) hostIndex = path.Length; return path.Substring(schemaIndex, hostIndex - schemaIndex); } public static AsyncFtpClient GetFtpClient(string ftpPath) { var host = GetFtpHost(ftpPath); var port = GetFtpPort(ftpPath); var credentials = FtpManager.Credentials.Get(host, FtpManager.Anonymous); return new(host, credentials, port); } } }