예제 #1
0
        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);
        }
예제 #3
0
        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>());
        }
예제 #4
0
        public void RemoveDirectoryIsCalled()
        {
            var serviceUnderTest = new FtpService(_mockLog, _testWebService);

            serviceUnderTest.DeleteAll(_testSettings);
            _testWebService.Received().RemoveDirectory(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
예제 #5
0
        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);
                }
            }
        }
예제 #6
0
        public ConfigurationViewModel()
        {
            _googleDriveService = GetProvider <FtpService>();
            _googleDriveService.AccountAdded   += OnAccountAddedOrRemoved;
            _googleDriveService.AccountRemoved += OnAccountAddedOrRemoved;

            Configuration = _googleDriveService.GetConfiguration <ConfigModel>();
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
 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);
 }
예제 #11
0
        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);
        }
예제 #13
0
        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]);
        }
예제 #14
0
        public void CreateListOfRemoteFilesTest()
        {
            var copyContent = new Dictionary <string, bool>
            {
                { "/test.jpg", true }
            };
            var item = FtpService.CreateListOfRemoteFiles(copyContent).ToList();

            Assert.AreEqual("//test.jpg", item.FirstOrDefault());
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #19
0
        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}");
        }
예제 #20
0
파일: Lab4ViewModel.cs 프로젝트: wornr/PS
        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();
            }
        }
예제 #21
0
        /// <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);
        }
예제 #22
0
        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)
            };
        }
예제 #23
0
        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();
        }
예제 #24
0
        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);
        }
예제 #25
0
        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}");
        }
예제 #26
0
        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);
        }
예제 #27
0
        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);
        }
예제 #28
0
        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,
        }
예제 #29
0
파일: Program.cs 프로젝트: yarx/FtpCleaner
        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.")
            });
예제 #30
0
        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("上传失败");
            }
        }
예제 #31
0
        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;
            }
        }