private static bool sendCommand(string command) { //LinuxTreeViewItem.ReconnectServer(); //LinuxTreeViewItem.ReConnect(); if (!SSHController.ReConnect(timeout_connect_ms)) { return(false); } try { // send if (shell_stream_reader != null) { shell_stream_writer.Write(command); shell_stream_writer.Write("\n"); shell_stream_writer.Flush(); Log.PrintConsole(command, "send command" /*, test4.m_wnd.richTextBox_status*/); return(true); } } catch (Exception ex) { Log.PrintError(ex.Message, "send command", Status.current.richTextBox_status); } return(false); }
static bool UploadFile(string local_path, string remote_directory) { //LinuxTreeViewItem.ReconnectServer(); //LinuxTreeViewItem.ReConnect(); if (!SSHController.ReConnect(timeout_connect_ms)) { return(false); } try { FileInfo fi = new FileInfo(local_path); if (fi.Exists) { FileStream fs = File.Open(local_path, FileMode.Open, FileAccess.Read); sftp.UploadFile(fs, remote_directory + fi.Name); Log.PrintConsole(fi.Name + " => " + remote_directory + fi.Name, "upload file" /*, test4.m_wnd.richTextBox_status*/); SSHController.filename_uploaded = fi.Name; fs.Close(); } else { Log.PrintError("check the config file path", "upload file", Status.current.richTextBox_status); return(false); } } catch (Exception e) { Log.PrintError(e.Message, "UploadFile", Status.current.richTextBox_status); return(false); } return(true); }
public static SftpFile[] PollListInDirectory(string Path) { if (!SSHController.ReConnect(timeout_connect_ms)) { return(null); } // path 가 null 이라면 root if (Path == null) { Path = LinuxTreeViewItem.root.Path = sftp.WorkingDirectory; } return(_PollListInDirectory(Path)); }
private static bool downloadFile(string local_path_folder, string local_file_name, string remote_path_file, string filename = null) { //LinuxTreeViewItem.ReconnectServer(); //LinuxTreeViewItem.ReConnect(); if (!SSHController.ReConnect(timeout_connect_ms)) { return(false); } try { if (filename == null) { string[] split = remote_path_file.Split('/'); filename = split[split.Length - 1]; } string local; if (local_file_name != null) { local = local_path_folder + local_file_name; } else { local = local_path_folder + filename; } FileContoller.CreateDirectory(local_path_folder); FileStream fs = new FileStream(local, FileMode.Create); sftp.DownloadFile(remote_path_file, fs); Log.PrintConsole(filename + " => " + local, "downloadFile" /*, test4.m_wnd.richTextBox_status*/); fs.Close(); } catch (Exception e) { Log.PrintError(e.Message, "downloadFile", Status.current.richTextBox_status); return(false); } return(true); }