Ejemplo n.º 1
0
        private static bool downloadDirectory(string local_folder_path, string remote_directory_path, Regex filter_file = null, Regex filter_except_dir = null)
        {
            //LinuxTreeViewItem.ReconnectServer();
            //LinuxTreeViewItem.ReConnect();
            if (!SSHController.ReConnect(timeout_connect_ms))
            {
                return(false);
            }

            try
            {
                FileContoller.CreateDirectory(local_folder_path);

                SftpFile[] files = PullListInDirectory(remote_directory_path);
                for (int i = 0; i < files.Length; i++)
                {
                    if (files[i].Name == "." || files[i].Name == "..")
                    {
                        continue;
                    }

                    if (files[i].IsDirectory &&
                        (filter_except_dir == null || !filter_except_dir.IsMatch(files[i].Name)))
                    {
                        string re_local_folder_path = local_folder_path + files[i].Name + @"\";
                        downloadDirectory(re_local_folder_path, files[i].FullName, filter_file, filter_except_dir);
                        continue;
                    }

                    if (filter_file != null && !filter_file.IsMatch(files[i].Name))
                    {
                        continue;
                    }

                    downloadFile(local_folder_path, files[i].FullName, files[i].Name, files[i].Name);
                }
            }
            catch (Exception e)
            {
                Log.PrintError(e.Message, "downloadFile", Status.current.richTextBox_status);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static bool downloadFile(string local_path_folder, string remote_path_file, string local_file_name = null, string remote_filename = null)
        {
            //LinuxTreeViewItem.ReconnectServer();
            //LinuxTreeViewItem.ReConnect();
            if (!SSHController.ReConnect(timeout_connect_ms))
            {
                return(false);
            }

            try
            {
                if (remote_filename == null)
                {
                    string[] split = remote_path_file.Split('/');
                    remote_filename = split[split.Length - 1];
                }

                string local;
                if (local_file_name != null)
                {
                    local = local_path_folder + local_file_name;
                }
                else
                {
                    local = local_path_folder + remote_filename;
                }

                FileContoller.CreateDirectory(local_path_folder);

                FileStream fs = new FileStream(local, FileMode.Create);
                sftp.DownloadFile(remote_path_file, fs);
                Log.PrintConsole(remote_path_file + " => " + 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);
        }
Ejemplo n.º 3
0
        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);
        }