private void DoWork(object sender, DoWorkEventArgs e) { _sent = ""; try { var agencyName = "NoAgencyName"; var biosSn = "00000"; try { agencyName = Singleton.Agency.AgencyName; biosSn = Singleton.ProductActivation.BiosSn; agencyName = agencyName.Substring(0, agencyName.IndexOf(' ')); } catch { } var destination = PathUtil.GetServerLogPath(); var destFiName = agencyName + "_" + biosSn + "_" + DateTime.Now.Date.ToString("dd-MM-yy") + "_Log.txt"; var destpa = Path.Combine(destination, destFiName); using (var client = new WebClient()) { client.Credentials = DbCommandUtil.GetNetworkCredential(); client.UploadFile(destpa, _sourceLogFile); } } catch (Exception exception) { _sent = exception.Message; } }
public List <string> GetServerFileNames() { var listRequest = WebRequest.Create(PathUtil.GetDestinationPhotoPath()); listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails; listRequest.Credentials = DbCommandUtil.GetNetworkCredential(); var lines = new List <string>(); var lines2 = new List <string>(); using (var listResponse = listRequest.GetResponse()) using (var listStream = listResponse.GetResponseStream()) using (var listReader = new StreamReader(listStream)) { while (!listReader.EndOfStream) { var line = listReader.ReadLine(); lines.Add(line); } } foreach (var line in lines) { var tokens = line.Split(new[] { ' ' }, 9, StringSplitOptions.RemoveEmptyEntries); var name = tokens[3]; lines2.Add(name); } return(lines2); }
private void UploadFiles(IEnumerable <string> fileNames) { using (var client = new WebClient()) { client.Credentials = DbCommandUtil.GetNetworkCredential(); foreach (var fileName in fileNames) { var destpa = new Uri(Path.Combine(_destination, fileName)); var sourceLogFile = Path.Combine(_sourceFile, fileName); try { client.UploadFile(destpa, WebRequestMethods.Ftp.UploadFile, sourceLogFile); } catch (Exception ex) { LogUtil.LogError(ErrorSeverity.Critical, "FileUploader.UploadFile problem", ex.Message + Environment.NewLine + ex.InnerException, "", ""); } } } }