public void RunFileMv() { if (MySshTool.SshMvAllFileAsyn("192.168.200.153", "root", "B2CCentOs7!", @"F:\file\Code\SharpSSH-1.1.1.13.src", @"/usr/lijie", new Action <string>((str) => Console.WriteLine(str)), new Action <string>((str) => Console.WriteLine("********************************" + str)))) { Console.WriteLine("______________________________________"); Console.WriteLine("SshMvAllFileAsyn TRUE"); Console.WriteLine("______________________________________"); } }
public void RunTest() { Console.WriteLine("文件传输"); sshCp.Connect(); string localPath = @"F:\file\Code\SharpSSH-1.1.1.13.src"; string serverPath = @"/usr/lijie"; FileInfo[] distFIles = FileService.GetAllFiles(localPath); if (distFIles == null) { Console.WriteLine("没有发现更新文件"); //exec.Close(); sshCp.Close(); } Console.WriteLine("开始更新"); foreach (FileInfo tempFileInfo in distFIles) { string tempNowPath = serverPath + tempFileInfo.DirectoryName.MyTrimStr(localPath, null).Replace(@"\", @"/") + @"/" + tempFileInfo.Name; try { sshCp.Put(tempFileInfo.DirectoryName + @"\" + tempFileInfo.Name, tempNowPath); } catch (Exception ex) { Console.WriteLine(ex.Message); //scp: /tmp/dist/123: No such file or directory if (ex.Message.Contains("No such file or directory")) { string tempPath = ex.Message; tempPath = tempPath.Remove(0, tempPath.IndexOf(@"/")); tempPath = tempPath.Remove(tempPath.LastIndexOf(@"/")); Console.WriteLine("创建文件夹" + tempPath); if (MySshTool.SshFileMkFullDir(sshCp, tempPath)) { try { sshCp.Put(tempFileInfo.DirectoryName + @"\" + tempFileInfo.Name, tempNowPath); } catch (Exception innerEx) { Console.WriteLine(innerEx.Message); Console.WriteLine("传输失败,跳过该文件"); } } else { Console.WriteLine("创建文件夹失败,跳过该文件"); } } } } Console.WriteLine("更新完成"); sshCp.Close(); }