/// <summary> /// 发送文件 /// </summary> public void SendFileToLF() { try { //读取send文件夹,发送到LFsftp //读取文件列表 string[] sendfiles = Directory.GetFiles(SFTPConstants.SendFilePath); if (sendfiles.Length > 0) { for (int i = 0; i < sendfiles.Length; i++) { WMS_NikeReturnSFTP_Log log = new WMS_NikeReturnSFTP_Log(); log.SourceFileName = sendfiles[i]; log.Type = "SendFile"; try { FileInfo file = new FileInfo(sendfiles[i]); string filename = file.Name; log.Str7 = SFTPConstants.sftpip; log.Str8 = SFTPConstants.sftpport; log.Str9 = SFTPConstants.sftpuser; log.Str10 = SFTPConstants.sftppwd; SFTPHelper sftp = new SFTPHelper(SFTPConstants.sftpip, SFTPConstants.sftpport, SFTPConstants.sftpuser, SFTPConstants.sftppwd); //string sftpfilepath = SFTPConstants.sftpfilepath + @"\" + filename; //发送文件 sftp.Put(sendfiles[i], filename); log.ToFileName = SFTPConstants.SentFilePath + @"\" + filename; log.Flag = "Y"; log.ResultDesc = "发送成功"; FileCommon.MoveToCover(log.SourceFileName, log.ToFileName); } catch (Exception ex) { log.Flag = "N"; log.ResultDesc = "发送失败:" + ex.Message.ToString(); } new LogOperationService().AddNikeReturnSFTPLog(log); } } } catch (Exception e) { WMS_NikeReturnSFTP_Log log = new WMS_NikeReturnSFTP_Log(); log.Type = "SendFile"; log.Flag = "N"; log.ResultDesc = e.Message.ToString(); new LogOperationService().AddNikeReturnSFTPLog(log); } }
public void ReadFile() { try { //读取文件列表 string[] receivefiles = Directory.GetFiles(SFTPConstants.ReceiveFilePath); if (receivefiles.Length > 0) { //TextHelper txthelper = new TextHelper(); for (int i = 0; i < receivefiles.Length; i++) { WMS_NikeReturnSFTP_Log log = new WMS_NikeReturnSFTP_Log(); log.SourceFileName = receivefiles[i]; FileInfo file = new FileInfo(receivefiles[i]); string filename = file.Name; string result = "";//解析的错误提示 string externumber = ""; try { List <string> txtlists = TextHelper.ReadTextFileToList(receivefiles[i]);//读取成list //没有数据 if (txtlists.Count() > 0) { //可以处理多个接口文件 switch (txtlists[0].ToString().Substring(0, 9).Trim()) { case "WMSSHP": //LF推给我们的出库单 log.Type = "WMSALLOC"; result = new WMSALLOCManage().LFOrderImportByLoadKey(txtlists, out externumber); break; default: log.Type = ""; result = "未能从文件中识别出对应的接口"; break; } if (result == "") { //解析成功,移动到success文件夹 log.ToFileName = SFTPConstants.SuccessFilePath + @"\" + log.Type + @"\" + filename; log.ResultDesc = "解析成功"; log.Str1 = externumber; log.Flag = "Y"; } else { if (log.Type != "") { if (result.Contains("数据库插入失败")) { log.ToFileName = "";// SFTPConstants.SuccessFilePath + @"\" + log.Type + @"\" + filename; log.ResultDesc = "解析失败:" + result; log.Str1 = externumber; log.Flag = "E"; } else { log.ToFileName = SFTPConstants.FaildFilePath + @"\" + log.Type + @"\" + filename;//移动到解析失败文件夹 log.ResultDesc = "解析失败:" + result; log.Str1 = externumber; log.Flag = "N"; } } else { log.ToFileName = SFTPConstants.ErrorFilePath + @"\" + filename; log.ResultDesc = "解析失败:" + result; log.Str1 = externumber; log.Flag = "N"; } } } else { log.ToFileName = SFTPConstants.ErrorFilePath + @"\" + filename; log.Flag = "N"; log.ResultDesc = "解析失败:文档中无数据"; } } catch (Exception ex) { //报错了放到error文件 log.ToFileName = SFTPConstants.ErrorFilePath + @"\" + filename; log.Flag = "N"; log.ResultDesc = "解析报错:" + ex.Message.ToString(); } if (log.Flag == "E")//数据库失败再解析一次 { } else { FileCommon.MoveToCover(log.SourceFileName, log.ToFileName); } new LogOperationService().AddNikeReturnSFTPLog(log); } } } catch (Exception e) { WMS_NikeReturnSFTP_Log log = new WMS_NikeReturnSFTP_Log(); log.Flag = "N"; log.ResultDesc = "读取文件报错:" + e.Message.ToString(); new LogOperationService().AddNikeReturnSFTPLog(log); } }