コード例 #1
0
        private void buttonDownloadTestMaterial_Click(object sender, EventArgs e)
        {
            var files = Settings.Default.TestMaterials.Split(',');

            var ftpClient = new Ftp(@"ftp://" + this.textBoxFtpIp.Text, Settings.Default.FtpUserName, Settings.Default.FtpPassword);

            var    downloadFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string drive = Path.GetPathRoot(@"D:\");

            if (!this.checkBoxDesktop.Checked && Directory.Exists(drive))
            {
                downloadFolderPath = drive;
            }

            Parallel.ForEach(files, currentFile =>
            {
                // The more computational work you do here, the greater
                // the speedup compared to a sequential foreach loop.
                var filepathname = Path.Combine(downloadFolderPath, currentFile);
                if (File.Exists(filepathname))
                {
                    File.Delete(filepathname);
                }

                ftpClient.download(currentFile, filepathname);
                // Peek behind the scenes to see how work is parallelized.
                // But be aware: Thread contention for the Console slows down parallel loops!!!
                Console.WriteLine("Processing {0} on thread {1}", filepathname,
                                  Thread.CurrentThread.ManagedThreadId);
            }                   //close lambda expression
                             ); //close method invocation
        }
コード例 #2
0
        private void timerUpload_Tick(object sender, EventArgs e)
        {
            this.timerUpload.Enabled = false;
            string zipPath   = getZipPath();
            var    ftpClient = new Ftp(@"ftp://" + this.textBoxFtpIp.Text, Settings.Default.FtpUserName, Settings.Default.FtpPassword);
            string tempFile  = "T" + zipPath;

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }
            File.Copy(zipPath, tempFile);
            ftpClient.delete(zipPath);
            var value = ftpClient.upload(zipPath, Path.Combine(Directory.GetCurrentDirectory(), tempFile));

            Console.WriteLine("Uploaded!" + value);
        }
コード例 #3
0
        private void buttonUploadYourTestWork_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "Test files(*.7z;*.zip)|*.7z;*.zip|All files (*.*)|*.* ";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Multiselect      = true;


            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var ftpClient = new Ftp(@"ftp://" + this.textBoxFtpIp.Text, Settings.Default.FtpUserName, Settings.Default.FtpPassword);

                var ip = LocalIPAddress().Replace(".", "_");
                ftpClient.createDirectory(ip);

                Parallel.ForEach(openFileDialog1.FileNames, currentFilePathName =>
                {
                    var currentFileName     = Path.GetFileName(currentFilePathName);
                    string tempFilePathName = Path.Combine(Path.GetDirectoryName(currentFilePathName), "T" + currentFileName);
                    if (File.Exists(tempFilePathName))
                    {
                        File.Delete(tempFilePathName);
                    }
                    File.Copy(currentFilePathName, tempFilePathName);

                    // ftpClient.delete(ip + "/" + currentFileName);

                    var value = ftpClient.upload(ip + "/" + currentFileName, tempFilePathName);
                    // Peek behind the scenes to see how work is parallelized.
                    // But be aware: Thread contention for the Console slows down parallel loops!!!
                    Console.WriteLine("Processing {0} on thread {1}", currentFileName,
                                      Thread.CurrentThread.ManagedThreadId);
                }                   //close lambda expression
                                 ); //close method invocation
            }
        }