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); }
public static bool Write(string path, string str) { if (path == null || str == null) { return(false); } try { // 경로에 디렉토리가 없으면 생성 string dir = path; if (path[path.Length - 1] != '\\') { dir = path.Substring(0, path.LastIndexOf('\\') + 1); } FileContoller.CreateDirectory(dir); // 경로에 파일 쓰기. FileStream fs = new FileStream(path, FileMode.Create); byte[] buffer /* = new byte[MAX_BUFFER]*/; int size_write = 0; buffer = Encoding.UTF8.GetBytes(str); size_write = buffer.Length; fs.Write(buffer, 0, size_write); fs.Close(); return(true); } catch (Exception e) { Log.PrintConsole(e.Message, "FileContoller.Write"); } return(false); }