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 (); }); }
public static bool load(string qrc) { // qrc for the just detected QR Code string manifest = qrc.Substring(0,6) ; if (Folder.GetFiles(manifest).Length == 0) { // manifest not present locally Credentials credentials = new Credentials() ; FTPSClient ftp = new FTPSClient() ; ftp.Connect(credentials.ftpServer, new NetworkCredential(credentials.username, credentials.password), ESSLSupportMode.CredentialsRequested) ; ftp.GetFile(credentials.bankRelPath + "/atm/" + manifest + "/keyFile", Folder.FullName + Path.DirectorySeparatorChar + manifest) ; ftp.Close() ; } FileInfo[] m = Folder.GetFiles(manifest) ; // there should be just one foreach (FileInfo f in m) Manifest.load(f) ; return true ; }
public static bool load(string qrc) { // qrc for the just detected QR Code mutex.WaitOne(); string manifest = qrc.Substring(0, 6); bool sthLoaded = false; if (Folder.GetFiles(manifest).Length == 0) { // manifest not present locally Credentials credentials = new Credentials(); FTPSClient ftp = new FTPSClient(); ftp.Connect(credentials.ftpServer, new NetworkCredential(credentials.username, credentials.password), ESSLSupportMode.CredentialsRequested); ftp.GetFile(credentials.root + "/atm/" + manifest + "/keyFile", Folder.FullName + Path.DirectorySeparatorChar + manifest); ftp.Close(); } FileInfo[] m = Folder.GetFiles(manifest); // there should be just one foreach (FileInfo f in m) sthLoaded |= Manifest.load(f); // returns false if manifest already in DOM mutex.ReleaseMutex(); return sthLoaded; }
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(); })); } }