public static async ValueTask <bool> ConnectAsync(this IFtpClient ftpClient, Uri uri, CancellationToken token = default) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } var(hostName, address, port, encryptionLevel) = GetDetailsFromUri(uri); if (address != null && await ftpClient.ConnectAsync(address, port, encryptionLevel, token)) { return(true); } var hostAddresses = Dns.GetHostAddresses(hostName); foreach (var hostAddress in hostAddresses) { if (await ftpClient.ConnectAsync(hostAddress, port, encryptionLevel, token)) { return(true); } } return(false); }
public async Task SyncDirectory(SiteSetting site, string siteKey) { _logger.LogInformation($"Starting sync {siteKey}"); try { _client.Host = site.FtpServer; _client.Credentials = new System.Net.NetworkCredential(site.UserName, site.Password); await _client.ConnectAsync(); await _client.DownloadFolderRecursive(site.RootFolder[0], site.DestinationFolder); _logger.LogInformation($"Finish sync {siteKey}"); } catch (FtpException exc) { _logger.LogError(exc, $"Error processing site {siteKey}"); } finally { if (_client.IsConnected) { await _client.DisconnectAsync(); } } }
private async Task _EnsureConnection() { if (_ftpClient.IsConnected) { return; } if (_options.AutoConnect) { await _ftpClient.AutoConnectAsync(); return; } _ftpClient.DataConnectionType = _options.DataConnectionType; _ftpClient.EncryptionMode = _options.EncryptionMode; _ftpClient.SslProtocols = _options.SslProtocol; _ftpClient.RetryAttempts = _options.RetryAttempts; _ftpClient.SocketPollInterval = _options.SocketPollInterval; _ftpClient.ConnectTimeout = _options.Timeout; _ftpClient.DataConnectionConnectTimeout = _options.Timeout; _ftpClient.DataConnectionReadTimeout = _options.Timeout; _ftpClient.ReadTimeout = _options.Timeout; _ftpClient.ValidateAnyCertificate = true; await _ftpClient.ConnectAsync(); }
public static ValueTask <bool> ConnectAsync(this IFtpClient ftpClient, CancellationToken token = default) { return(ftpClient.ConnectAsync(ftpClient.HostAddress, ftpClient.HostPort, ftpClient.EncryptionLevel, token)); }
/// <inheritdoc /> public Task InitializeAsync() { return(_client.ConnectAsync()); }