Esempio n. 1
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);
        }
Esempio n. 2
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
            }
        }