Пример #1
0
        public static void start()
        {
            DirectoryInfo  within = new DirectoryInfo (source);
             FileInfo[]     files = within.GetFiles ();
             int            nFiles = files.Length,index = 0;
             float          fraction = 0;
             Credentials    credentials = new Credentials ();

             string target = credentials.bankRelPath + "/staging/";

             FTPSClient client = new FTPSClient ();
             client.Connect (credentials.ftpServer,
                         new NetworkCredential (credentials.username, credentials.password),
                         ESSLSupportMode.CredentialsRequested);

             client.SetTransferMode (ETransferMode.Binary);

             foreach (FileInfo f in files) {
            index += 1;
            fraction = ((float)index) / nFiles;
            try {
               client.PutFile (f.FullName, target + f.Name);
            } catch {
               // Console.WriteLine (" -- putfile exception");
               client.Close ();
               client = new FTPSClient ();
               client.Connect (credentials.ftpServer,
                         new NetworkCredential (credentials.username, credentials.password),
                         ESSLSupportMode.CredentialsRequested);
               client.SetTransferMode (ETransferMode.Binary);
               client.PutFile (f.FullName, target + f.Name);
            }
            Gtk.Application.Invoke (delegate {
               MainClass.getAppWindow ().getTransmissionPBar ().Fraction = fraction;});
            f.Delete() ; // delete the file from within .resolved/
             }
             client.Close ();

             Gtk.Application.Invoke (delegate {
            MainClass.doneTransmitting ();
            MainClass.resetDisplay (); });
        }
Пример #2
0
        public static void start()
        {
            DirectoryInfo within = new DirectoryInfo(source);
              FileInfo[] files = within.GetFiles();
              int nFiles = files.Length, processed = 0;
              int percentDone = 0;
              Credentials credentials = new Credentials();

              string target = credentials.target + "/staging/";
              Stopwatch stopWatch = new Stopwatch();
              FTPSClient client = new FTPSClient();
              string welcomeMsg = null;

              System.Diagnostics.Debug.WriteLine("[Transmitter]: Thread start()");

              try {
            welcomeMsg = client.Connect(credentials.ftpServer,
                    new NetworkCredential(credentials.username, credentials.password),
                    ESSLSupportMode.CredentialsRequested);
              } catch (SocketException e) {
            Program.Gui.Invoke((MethodInvoker)(delegate {
              Program.EstTransmission.Text = "No Net?";
              Label noNet = Program.Gui.NetConnectionStatus;

              noNet.Text = "Just make sure you're connected to the Net. I will try again later";
              noNet.Visible = true;
            }));
            client.Close();
            return;
              }

              // Have net ... Try logging in to FTP server

              if (welcomeMsg.StartsWith("Login successful")) {
            Program.Gui.Invoke((MethodInvoker)(delegate {
              Program.EstTransmission.Text = "Connected";
              Program.Gui.NetConnectionStatus.Visible = false;
            }));
              } else {
            Program.Gui.Invoke((MethodInvoker)(delegate {
              Program.EstTransmission.Text = "Couldn't login";
              Label noNet = Program.Gui.NetConnectionStatus;

              noNet.Text = "Happens sometimes. Not to worry. I will try again later";
              noNet.Visible = true;
            }));
            client.Close();
            return;
              }

              // Otherwise, we are good to go
              client.SetTransferMode(ETransferMode.Binary);
              stopWatch.Start();

              foreach (FileInfo f in files) {
            if (!Program.GuiAlive) {
              System.Diagnostics.Debug.WriteLine("[Transmitter]: Gui Dead!!");
              break;
            }

            ulong bytesSent = 0;
            ulong size = (ulong)f.Length;

            try {
              bytesSent = client.PutFile(f.FullName, target + f.Name);
            } catch {
              // Console.WriteLine (" -- putfile exception");
              client.Close();
              client = new FTPSClient();
              client.Connect(credentials.ftpServer,
                    new NetworkCredential(credentials.username, credentials.password),
                    ESSLSupportMode.CredentialsRequested);
              client.SetTransferMode(ETransferMode.Binary);
              bytesSent = client.PutFile(f.FullName, target + f.Name);
            }
            processed += 1;
            percentDone = (int)((processed * 100) / nFiles); // percentage

            TimeSpan elapsed = stopWatch.Elapsed;
            string estimate = Program.EstTimeToCompletion(elapsed, processed, nFiles);

            // Update the transmission progress bar
            if (Program.GuiAlive) {
              Program.Gui.Invoke((MethodInvoker)(delegate {
            Program.TransmissionBar.Value = percentDone;
            Program.EstTransmission.Text = estimate;
              }));
            }

            if (bytesSent == size)
              f.Delete();
            // delete file from .resolved/ only if it was transferred completely
              }

              stopWatch.Stop();
              client.Close();
              System.Diagnostics.Debug.WriteLine("[Transmitter]: Thread end()");

              if (Program.GuiAlive) {
            Program.Gui.Invoke((MethodInvoker)(delegate {
              Program.DoneTransmitting();
              Program.ResetDisplay();
            }));
              }
        }