Exemplo n.º 1
0
        private async void LoadFtp(string ftpDir, string locDir)
        {
            // Cancellation token
            CancellationTokenSource cts = new CancellationTokenSource();

            // The Progress<T> constructor captures our UI context,
            //  so the lambda will be run on the UI thread.
            var progress1 = new Progress <int>(percent1 =>
            {
                Var.TaskProgress1 = percent1;
            });
            var progressIndex = new Progress <int>(i =>
            {
                ListView1.SelectedIndex = i;
            });
            var progress2 = new Progress <int>(percent2 =>
            {
                Var.TaskProgress2 = percent2;
            });

            /* Create Object Instance */
            Ftp ftpClient = new Ftp(ftpDir, Var.FtpUsername1, Var.FtpPassword1);

            /* Get Contents of a Directory (Names Only) */
            IEnumerable <string> filesToLoad = ftpClient.DirectoryListSimple("").Except(IO.ListFileNamesFromFolder(locDir, "*.csv")).Take(Var.MaxFilesCount);
            await Task.Run(() => Var.ListView1Content = filesToLoad);

            // DoProcessing is run on the thread pool.
            await Task.Run(() => Ftp.LoadFtpFiles(filesToLoad, ftpDir, locDir, progress1, progress2, progressIndex));

            Var.TaskProgress1 = 0;
            Var.TaskProgress2 = 0;
        }
Exemplo n.º 2
0
        void Useftp()
        {
            /* Create Object Instance */
            Ftp ftpClient = new Ftp(@"ftp://10.10.10.10/", "user", "password");

            /* Upload a File */
            ftpClient.Upload("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt");

            /* Download a File */
            ftpClient.Download("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt");

            /* Delete a File */
            ftpClient.Delete("etc/test.txt");

            /* Rename a File */
            ftpClient.Rename("etc/test.txt", "test2.txt");

            /* Create a New Directory */
            ftpClient.CreateDirectory("etc/test");

            /* Get the Date/Time a File was Created */
            string fileDateTime = ftpClient.GetFileCreatedDateTime("etc/test.txt");
            //Console.WriteLine(fileDateTime);

            /* Get the Size of a File */
            string fileSize = ftpClient.GetFileSize("etc/test.txt");

            //Console.WriteLine(fileSize);

            /* Get Contents of a Directory (Names Only) */
            string[] simpleDirectoryListing = ftpClient.DirectoryListSimple("/etc");
            for (int i = 0; i < simpleDirectoryListing.Count(); i++)
            {
                Console.WriteLine(simpleDirectoryListing[i]);
            }

            /* Get Contents of a Directory with Detailed File/Directory Info */
            string[] detailDirectoryListing = ftpClient.DirectoryListDetailed("/etc");
            for (int i = 0; i < detailDirectoryListing.Count(); i++)
            {
                Console.WriteLine(detailDirectoryListing[i]);
            }

            /* Release Resources */
            ftpClient = null;
        }
Exemplo n.º 3
0
        public static async void LoadFtpFiles(IEnumerable <string> filesToLoad, string ftpDirSource, string locDirTarget, IProgress <int> progress1, IProgress <int> progress2, IProgress <int> progressIndex)
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            int i    = 0;
            int maxi = filesToLoad.Count();

            foreach (string fileName in filesToLoad)
            {
                //Fortschrittsanzeige
                if (progress1 != null)
                {
                    progress1.Report(++i * 100 / maxi);
                }
                if (progressIndex != null)
                {
                    progressIndex.Report(i);
                }

                //Wenn fileName leer, dann Schleife überspringen.
                if (fileName.Length == 0)
                {
                    continue;
                }

                Thread.Sleep(Var.SleepingMilliSec); // CPU-bound work

                // Start asyn operation
                Uri    ftpSite       = new Uri(Path.Combine(ftpDirSource, fileName));
                string locFileTarget = Path.Combine(locDirTarget, fileName);
                try
                {
                    await Ftp.DownloadFileAsync(ftpSite, locFileTarget, progress2, cts.Token);
                }
                catch (Exception ex)
                {
                    IO.Log(2018062005, ftpSite + " => " + locFileTarget + " | " + ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        private void Button_ListFilesFromFolder_Click(object sender, RoutedEventArgs e)
        {
            switch (ComboBox_ListToShow.SelectedIndex)
            {
            case 0:
                ListView1.ItemsSource = IO.ListFileNamesFromFolder(Var.LocDirInput, "*.csv");
                break;

            case 1:
                Ftp ftp1 = new Ftp(Var.FtpDirInput, Var.FtpUsername1, Var.FtpPassword1);
                ListView1.ItemsSource = ftp1.DirectoryListSimple("");
                break;

            case 2:
                ListView1.ItemsSource = IO.ListFileNamesFromFolder(Var.LocDirOperation, "*.csv");
                break;

            case 3:
                Ftp ftp3 = new Ftp(Var.FtpDirOperation, Var.FtpUsername1, Var.FtpPassword1);
                ListView1.ItemsSource = ftp3.DirectoryListSimple("");
                break;

            case 4:
                ListView1.ItemsSource = IO.ListFileNamesFromFolder(Var.LocDirScales, "*.csv");
                break;

            case 5:
                Ftp ftp5 = new Ftp(Var.FtpDirScales, Var.FtpUsername1, Var.FtpPassword1);
                ListView1.ItemsSource = ftp5.DirectoryListSimple("");
                break;

            default:
                ListView1.ItemsSource = null;
                break;
            }
        }
Exemplo n.º 5
0
 private void Button_CheckFtpDir_Click(object sender, RoutedEventArgs e)
 {
     status_FtpDirInput.Fill     = Ftp.DoesFtpDirectoryExist(Var.FtpDirInput);
     status_FtpDirOperation.Fill = Ftp.DoesFtpDirectoryExist(Var.FtpDirOperation);
     status_FtpDirScales.Fill    = Ftp.DoesFtpDirectoryExist(Var.FtpDirScales);
 }