void ButtonftptestClick(object sender, EventArgs e) { SaveConfig(); bool ftperror = false; FtpClient myFtpClient = new FtpClient(); myFtpClient.Server = GlobalVars.config_ftpserver; myFtpClient.Port = Convert.ToInt32(GlobalVars.config_ftpport); myFtpClient.Username = GlobalVars.config_ftpuser; myFtpClient.Password = GlobalVars.config_ftppass; try { myFtpClient.Login(); } catch (FtpClient.FtpException ex) { MessageBox.Show(GlobalVars.lang_couldnotlogintoserver + ": " + ex.Message, GlobalVars.lang_ftperror); ftperror = true; } try { myFtpClient.ChangeDir(GlobalVars.config_ftpuploaddir); } catch (FtpClient.FtpException ex) { MessageBox.Show(GlobalVars.lang_couldnotchangedirtouploaddirectory + ": " + ex.Message, GlobalVars.lang_ftperror); ftperror = true; } try { myFtpClient.Close(); } catch { } if (ftperror == false) { MessageBox.Show(GlobalVars.lang_ftpsettingssuccessfullytested, GlobalVars.lang_ftpsettingssuccessfullytested); } }
void FtpUpload() { GlobalVars.ftpthreadIsActive = true; // Lock this function updateTemperLabel(99); DateTime mydt = DateTime.Now; string currentday = mydt.ToString("yyyy-MM-dd"); FtpClient myFtpClient = new FtpClient(); myFtpClient.Server = GlobalVars.config_ftpserver; myFtpClient.Port = Convert.ToInt32(GlobalVars.config_ftpport); myFtpClient.Username = GlobalVars.config_ftpuser; myFtpClient.Password = GlobalVars.config_ftppass; bool ftperror = false; log("FTP Client Started: " + myFtpClient.Server + ":" + myFtpClient.Port + "; " + myFtpClient.Username + "/" + myFtpClient.Password); try { myFtpClient.Login(); } catch (FtpClient.FtpException ex) { log("FTP Client Login ERROR: " + ex.Message); showStatus("FTP ERROR: " + ex.Message); ftperror = true; } if (!ftperror) log("FTP Client Logged In"); if (!ftperror) { try { myFtpClient.ChangeDir(GlobalVars.config_ftpuploaddir); } catch (FtpClient.FtpException ex) { showStatus("FTP ERROR: " + ex.Message); ftperror = true; } } if (!ftperror) { string myfilename; if (GlobalVars.config_csv) { if (GlobalVars.config_dailyfiles) { myfilename = GlobalVars.config_filepath + "\\" + "TEMPer-" + currentday + ".csv"; } else { myfilename = GlobalVars.config_filepath + "\\" + "TEMPer.csv"; } } else { if (GlobalVars.config_dailyfiles) { myfilename = GlobalVars.config_filepath + "\\" + "TEMPer-" + currentday + ".txt"; } else { myfilename = GlobalVars.config_filepath + "\\" + "TEMPer.txt"; } } try { myFtpClient.BinaryMode = false; myFtpClient.Upload(myfilename); } catch (FtpClient.FtpException ex) { showStatus(GlobalVars.lang_couldnotuploadfile + ": " + ex.Message); ftperror = true; } if (GlobalVars.config_graph && GlobalVars.config_ftpuploadgraph) { int i; for (i = 0; i < GlobalVars.devicecount; i++) { String graphuploadpath = GlobalVars.config_filepath + "\\" + "utac" + i + ".jpeg"; try { GlobalVars.graphPicture[i].Save(graphuploadpath, System.Drawing.Imaging.ImageFormat.Jpeg); myFtpClient.BinaryMode = true; myFtpClient.Upload(graphuploadpath); // File.Delete(graphuploadpath); } catch (Exception ex) { showStatus(GlobalVars.lang_couldnotuploadfile + ": " + ex.Message); } } } } try { myFtpClient.Close(); } catch (Exception ex) { showStatus("FTP Close Error: " + ex.Message); GlobalVars.ftpthreadIsActive = false; // Unlock this function updateTemperLabel(99); } GlobalVars.ftpthreadIsActive = false; // Unlock this function updateTemperLabel(99); }