public async Task TestWebGenerationConnection(FtpService ftpService) { try { string path = Model.WebGenerationModel.Path; if (Model.WebGenerationModel.FtpModeEnabled) { string host = Model.WebGenerationModel.Server; int port = Model.WebGenerationModel.Port; string username = Model.WebGenerationModel.Username; string password = Model.WebGenerationModel.Password; var ftpMode = Model.WebGenerationModel.FtpMode; await Task.Run(() => ftpService.CheckConnection(host, port, path, username, password, ftpMode)).ConfigureAwait(false); } else { if (!Directory.Exists(path)) { throw new DirectoryNotFoundException($"{path} does not exist."); } } } catch (Exception ex) { Logger.Error(ex.Message, ex); throw; } }
protected override void RunTool() { var ftpService = new FtpService(_log, _testWebService); var tool = new FtpDeployRunner <TSettings>(FileSystem, Environment, ProcessRunner, Tools, ftpService); tool.Execute(Settings); }
public void DeleteFileIsCalledSixTimes() { var serviceUnderTest = new FtpService(_mockLog, _testWebService); serviceUnderTest.DeleteAll(_testSettings); _testWebService.Received(6).DeleteFile(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public void RemoveDirectoryIsCalled() { var serviceUnderTest = new FtpService(_mockLog, _testWebService); serviceUnderTest.DeleteAll(_testSettings); _testWebService.Received().RemoveDirectory(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public void GetFileListFromFtp_Ok() { // Arrange var ftpClient = new FtpService(ConfigurationService); // Act var fileList = ftpClient.GetFileList(); // Assert Check.That(fileList).Not.IsEmpty(); if (fileList.Count >= 2) { for (int i = 0; i < fileList.Count - 2; i++) { var current = fileList[i]; var next = fileList[i + 1]; var currentValue = int.Parse(Path.GetFileNameWithoutExtension(current)); var nextValue = int.Parse(Path.GetFileNameWithoutExtension(next)); Check.That(currentValue).IsBefore(nextValue); } } }
public ConfigurationViewModel() { _googleDriveService = GetProvider <FtpService>(); _googleDriveService.AccountAdded += OnAccountAddedOrRemoved; _googleDriveService.AccountRemoved += OnAccountAddedOrRemoved; Configuration = _googleDriveService.GetConfiguration <ConfigModel>(); }
public void DoesFtpDirectoryExist_NonExist() { var factory = new FakeIFtpWebRequestFactory(); var item = new FtpService(_appSettings, _storage, new FakeConsoleWrapper(), factory); var result = item.DoesFtpDirectoryExist("/web-exception"); Assert.IsFalse(result); }
public void CreateFtpDirectory() { var factory = new FakeIFtpWebRequestFactory(); var item = new FtpService(_appSettings, _storage, new FakeConsoleWrapper(), factory); var result = item.CreateFtpDirectory("/new-folder"); Assert.IsTrue(result); }
public void CreateFtpDirectory_Fail() { var factory = new FakeIFtpWebRequestFactory(); var ftpService = new FtpService(_appSettings, _storage, new FakeConsoleWrapper(), factory); var result = ftpService.CreateFtpDirectory("/web-exception"); Assert.IsFalse(result); }
public ArchivingToFtp(string remotePath, string localFolder, int maxArchivingIntervalInHours, string login = "", string password = "") : base(maxArchivingIntervalInHours) { RemotePath = remotePath; LocalFolder = localFolder; this.login = login; this.password = password; ftp = new FtpService(login, password); }
public ConfigurationViewModel() { _service = GetProvider <FtpService>(); ClearAction(); _config = _service.GetConfiguration <ConfigModel>(); Accounts = new ObservableCollection <AccountModel>(_config.Accounts); }
public static void FtpDeploy(this ICakeContext context, FtpDeploySettings settings) { var webService = new WebService(); var ftpService = new FtpService(context.Log, webService); var runner = new FtpDeployRunner <FtpDeploySettings>(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, ftpService); runner.Execute(settings); }
public void CreateListOfRemoteDirectories_default() { var item = new FtpService(_appSettings, _storage, new FakeConsoleWrapper(), new FakeIFtpWebRequestFactory()) .CreateListOfRemoteDirectories("/", "item-name", new Dictionary <string, bool>()).ToList(); Assert.AreEqual("ftp://testmedia.be/", item[0]); Assert.AreEqual("ftp://testmedia.be//item-name", item[1]); }
public void CreateListOfRemoteFilesTest() { var copyContent = new Dictionary <string, bool> { { "/test.jpg", true } }; var item = FtpService.CreateListOfRemoteFiles(copyContent).ToList(); Assert.AreEqual("//test.jpg", item.FirstOrDefault()); }
public void MakeUpload_Fail_FileNotFound() { var factory = new FakeIFtpWebRequestFactory(); var ftpService = new FtpService(_appSettings, _storage, new FakeConsoleWrapper(), factory); // And Fail var makeUpload = ftpService.MakeUpload("/", "test", new List <string> { "/test" }); Assert.IsFalse(makeUpload); }
public void Run_UploadFail() { var factory = new FakeIFtpWebRequestFactory(); var ftpService = new FtpService(_appSettings, _storage, new FakeConsoleWrapper(), factory); var makeUpload = ftpService.Run("/", "test", new Dictionary <string, bool> { { "non-existing-file.jpg", true } }); Assert.IsFalse(makeUpload); }
public void CreateListOfRemoteDirectories_default_useCopyContent() { var item = new FtpService(_appSettings, _storage, new FakeConsoleWrapper(), new FakeIFtpWebRequestFactory()) .CreateListOfRemoteDirectories("/", "item-name", new Dictionary <string, bool> { { "large/test.jpg", true } }).ToList(); // start with index 2 Assert.AreEqual("ftp://testmedia.be//item-name//large", item[2]); }
/// <summary> /// SCORM Engine Service constructor that takes a single configuration parameter /// </summary> /// <param name="config">The Configuration object to be used to configure the Scorm Engine Service client</param> public ScormEngineService(Configuration config) { System.Net.ServicePointManager.Expect100Continue = false; configuration = config; courseService = new CourseService(configuration, this); dispatchService = new DispatchService(configuration, this); registrationService = new RegistrationService(configuration, this); invitationService = new InvitationService(configuration, this); uploadService = new UploadService(configuration, this); ftpService = new FtpService(configuration, this); exportService = new ExportService(configuration, this); reportingService = new ReportingService(configuration, this); debugService = new DebugService(configuration, this); }
private static void PassiveFtpModeExample() { var factory = new FtpFactory { Host = Host, User = User, Password = Pass, Type = FtpTypes.Ftp, Mode = FtpModes.Passive }; var service = new FtpService(factory); var items = service.GetListing(); Console.WriteLine($"Items found : {items.Count}"); }
private void Connect() { LoadConfig(); _ftpService = new FtpService(_config.Ftp.Host, _config.Ftp.Port, _config.Ftp.Username, _config.Ftp.Password, _config.Ftp.KeepAlive); ActualDir = _ftpService.Pwd(); if (_ftpService.Connected) { ConnectionStatusDescription = "Połączono"; ConnectionStatusColor = Brushes.Green; ListActual(); } }
private async void SetLocalRootDirectory() { var folderPicker = new FolderPicker(); folderPicker.FileTypeFilter.Add("*"); var folder = await folderPicker.PickSingleFolderAsync(); var localDirectory = new LocalDirectory(folder); var items = FtpService.CreatDirectoryItemViewModels(localDirectory); LocalWorkingDirectory = new LocalWorkingDirectoryViewModel { WorkingDirectory = localDirectory, Items = new ObservableCollection <ILocalDirectoryItemViewModel>(items) }; }
private static void Main() { // Add log file (static applied to all instances) FtpService.AddFileListner(@"ftp.log"); // Example of ftp passive mode PassiveFtpModeExample(); // Example of ftps passive mode PassiveFtpsModeExample(); // Example of ftp active mode ActiveFtpModeExample(); // Example of ftps active mode ActiveFtpsModeExample(); }
public void MakeUpload_AndFile_Is_Found() { var factory = new FakeIFtpWebRequestFactory(); var fakeStorage = new FakeIStorage(new List <string> { "/" }, new List <string> { "//test.jpg" }, new List <byte[]> { new byte[0] }); var ftpService = new FtpService(_appSettings, fakeStorage, new FakeConsoleWrapper(), factory); var makeUpload = ftpService.MakeUpload("/", "test", new List <string> { "/test.jpg" }); Assert.IsTrue(makeUpload); }
private static void ActiveFtpModeExample() { var factory = new FtpFactory { Host = Host, User = User, Password = Pass, Type = FtpTypes.Ftp, Mode = FtpModes.Active, ActivePorts = new List <int> { 32490, 32491, 32492 } }; var service = new FtpService(factory); var items = service.GetListing(); Console.WriteLine($"Items found : {items.Count}"); }
public void Run_UploadDone() { var factory = new FakeIFtpWebRequestFactory(); var fakeStorage = new FakeIStorage(new List <string> { "/" }, new List <string> { "//test.jpg" }, new List <byte[]> { new byte[0] }); var ftpService = new FtpService(_appSettings, fakeStorage, new FakeConsoleWrapper(), factory); var makeUpload = ftpService.Run("/", "test", new Dictionary <string, bool> { { "test.jpg", true } }); Assert.IsTrue(makeUpload); }
internal IFileService GetFileService(string fileServiceType) { IFileService fileService = null; if (fileServiceType.Equals(FILESERVICE_FILE, StringComparison.CurrentCultureIgnoreCase)) { ILogger <FileDirectoryService> log = _logger.CreateLogger <FileDirectoryService>(); fileService = new FileDirectoryService(_dataAccessor, log, _configService); } else if (fileServiceType.Equals(FILESERVICE_FTP, StringComparison.CurrentCultureIgnoreCase)) { ILogger <FtpService> log = _logger.CreateLogger <FtpService>(); fileService = new FtpService(log, _configService); } else //if (fileServiceType.Equals(FapFileService.FILESERVICE_DATABASE, StringComparison.CurrentCultureIgnoreCase)) { fileService = new DatabaseService(_dataAccessor); } return(fileService); }
static void Main(string[] args) { var configurator = new JsonConfigurator(); var result = configurator.LoadConfiguration <EncryptionConfiguration>(ConfigurationKeys.Encryption); var arguments = configurator.LoadConfiguration <DownloadArguments>(ConfigurationKeys.DownloadArguments); // This little stunt is done so that Encryption will load this correctly Config.Global.Add(ConfigurationKeys.Encryption, result); var ftpService = new FtpService(); var operation = ftpService.GetDownloadOperation(arguments.UserName, arguments.EncryptedPassword.Decrypt(), arguments.HostName, arguments.FtpPath, arguments.DestinationPath, TransferCallback); operation.StartDownload(); //ftpDownload.Password = arguments.EncryptedPassword; // Password = password, // HostName = hostName, }
public static async Task Main(string[] args) { var switchMappings = new Dictionary <string, string>() { { "-path", "Path" }, { "-host", "Url" }, { "-user", "Username" }, { "-pw", "Password" }, }; var configuration = new ConfigurationBuilder() .AddUserSecrets(typeof(MainClass).Assembly) .AddCommandLine(args, switchMappings) .Build(); // check if ftp action is specified; FtpAction action; try { action = Enum.Parse <FtpAction>(args[0], true); } catch { throw new Exception("Please specify FTP Action (clean or upload) as a first argument."); } var ftpInput = new FtpInput { Action = action, Path = configuration["Path"], Url = configuration["Url"], Username = configuration["Username"], Password = configuration["Password"] }; var ftpService = new FtpService(ftpInput.Url, ftpInput.Username, ftpInput.Password); await((ftpInput.Action, ftpInput.Path) switch { (FtpAction.Clean, _) => ftpService.Clean(), (FtpAction.Upload, null) => ftpService.Upload(), (FtpAction.Upload, _) => ftpService.Upload(ftpInput.Path), _ => throw new Exception("Input seems not to be correct. Please verify command line arguments.") });
private void button9_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtUploadPath.Text)) { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { txtUploadPath.Text = openFileDialog.FileName; } } FtpConfigEntity ftpConfig = new FtpService().GetFirstFtpInfo(); try { FtpHelper.UploadFile(ftpConfig, txtUploadPath.Text); MessageBox.Show("上传成功"); } catch (Exception ex) { MessageBox.Show("上传失败"); } }
private void RefreshWorkingDirectory(string path) { var ftpAction = DependencyService.Resolve <IRetrieveDirectory>(); ftpAction.Path = path; ftpAction.FtpServer = FtpServer; ftpAction.Execute(); if (ftpAction.FailedToConnectToServer) { FailedToConnectToServer(); } else { var remoteWorkingDirectoryViewModel = DependencyService.Resolve <IRemoteWorkingDirectoryViewModel>(); remoteWorkingDirectoryViewModel.ServerPath = path; remoteWorkingDirectoryViewModel.Items = new ObservableCollection <IRemoteDirectoryItemViewModel>( FtpService.CreatDirectoryItemViewModels(ftpAction.DirectoryItems)); RemoteWorkingDirectory = remoteWorkingDirectoryViewModel; } }