public void Set_active_mode() { var source = new WaybillSource(); var client = source.CreateFtpClient(); Assert.That(client.PassiveMode, Is.True); source.FtpActiveMode = true; client = source.CreateFtpClient(); Assert.That(client.PassiveMode, Is.False); }
private void ReceiveDocuments(InboundDocumentType documentType, WaybillSource waybillSource, Uri uri) { var haveErrors = false; if (uri == null) { return; } _logger.InfoFormat("Попытка получения документов с FTP поставщика (код поставщика: {0}).\nТип документов: {1}.\nUrl: {2}", waybillSource.Id, documentType.DocType.GetDescription(), uri); try { using (var ftpClient = waybillSource.CreateFtpClient()) { ftpClient.Connect(uri.Host, uri.Port); ftpClient.Authenticate(waybillSource.UserName, waybillSource.Password); ftpClient.SetCurrentDir(uri.PathAndQuery); var files = ftpClient.GetList(); foreach (var file in files.Tables["DirInfo"].AsEnumerable()) { if (Convert.ToBoolean(file["IsDirectory"])) { continue; } Cancellation.ThrowIfCancellationRequested(); var source = file["Name"].ToString(); var sourceDate = Convert.ToDateTime(file["Date"]); var sourceLength = Convert.ToInt64(file["Size"]); var dest = Path.Combine(DownHandlerPath, source); try { ftpClient.ReceiveFile(source, dest); var destLenth = new FileInfo(dest).Length; if (destLenth != sourceLength) { _logger.WarnFormat("Не совпадает размер загруженного файла {0} {1} размер на ftp {2} полученный рамер {3}", uri, source, sourceLength, destLenth); continue; } var downloadedFile = new DownloadedFile(dest, sourceDate); ProcessFile(documentType, waybillSource, downloadedFile); ftpClient.DeleteFile(source); } catch (Exception e) { haveErrors = true; LogError(e, waybillSource, uri, documentType); } } } if (!haveErrors && _failedSources.Contains(waybillSource.Id)) { waybillSource.LastError = DateTime.Now; _failedSources.Remove(waybillSource.Id); _logger.WarnFormat("После возникновения ошибок загрузка накладных прошла успешно. Код поставщика: {0}", waybillSource.Id); } } catch (Exception e) { LogError(e, waybillSource, uri, documentType); } }