Esempio n. 1
0
 private void listView2_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (listView2.SelectedItems.Count > 0)
     {
         ListViewItem        row   = listView2.SelectedItems[0];
         ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry)row.Tag;
         if (entry.getAttrs().isDir())
         {
             if (entry.getFilename() == "..")
             {
                 // 上一层
                 OpenUpDir();
             }
             else
             {
                 // 进入下一层
                 OpenDownDir(getCurrDir() + entry.getFilename());
             }
         }
     }
 }
Esempio n. 2
0
        private void FileAttrForm_Load(object sender, EventArgs e)
        {
            this.Text = file.getFilename() + " 的属性";
            if (file.getAttrs().isDir())
            {
                text_type.Text       = "文件夹";
                icon.BackgroundImage = Properties.Resources.folder_64px;
            }
            else
            {
                text_type.Text = getFileExt(file.getFilename());
                icon.Image     = Properties.Resources.filen_64px;
            }
            text_name.Text     = file.getFilename();
            text_size.Text     = Utils.getFileSize(file.getAttrs().getSize());
            text_host.Text     = user.Host;
            text_location.Text = dir + file.getFilename();

            text_modified.Text = file.getAttrs().getMtimeString();
            text_owner.Text    = getFileOwner(file.getLongname(), 3);
            text_group.Text    = getFileOwner(file.getLongname(), 4);
            text_permiss.Text  = file.getAttrs().getPermissionsString();
        }
Esempio n. 3
0
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView2.SelectedItems.Count > 0)
            {
                ListViewItem        row   = listView2.SelectedItems[0];
                ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry)row.Tag;
                if (!entry.getAttrs().isDir())
                {
                    try
                    {
                        string resfile    = getCurrDir() + entry.getFilename();
                        string targetfile = MainForm.TEMP_DIR + string.Format("{0}.file", DateTime.Now.ToString("MMddHHmmss"));
                        targetfile = targetfile.Replace("\\", "/");

                        TextEditorForm editor = new TextEditorForm();
                        editor.Show(this);
                        editor.LoadRemoteFile(new ShellForm(this), resfile, targetfile);
                    }
                    catch { }
                }
            }
        }
Esempio n. 4
0
        public void LoadDirFilesToListView(string path, LoadFilesResult result = null)
        {
            this.BeginInvoke((MethodInvoker) delegate()
            {
                try
                {
                    if (null == sftpChannel)
                    {
                        return;
                    }
                    ArrayList files = sftpChannel.ls(path);
                    if (files != null)
                    {
                        ChannelSftp.LsEntry file = null;
                        listView2.Items.Clear();
                        LargeImages.Images.Clear();
                        SmallImages.Images.Clear();

                        LargeImages.Images.Add(Properties.Resources.filen_64px);
                        LargeImages.Images.Add(Properties.Resources.folder_64px);
                        SmallImages.Images.Add(Properties.Resources.filen_16px);
                        SmallImages.Images.Add(Properties.Resources.folder_16px);

                        ListViewItem item = null;
                        ListViewItem.ListViewSubItem subItem = null;
                        List <ListViewItem> itemList         = new List <ListViewItem>();
                        for (int i = 0; i < files.Count; i++)
                        {
                            object obj = files[i];
                            if (obj is ChannelSftp.LsEntry)
                            {
                                file = (ChannelSftp.LsEntry)obj;
                                if (file.getFilename() == ".")
                                {
                                    continue;
                                }

                                item      = new ListViewItem();
                                item.Text = file.getFilename();
                                item.Tag  = file;

                                if (file.getFilename() != "..")
                                {
                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = Utils.getFileSize(file.getAttrs().getSize());
                                    item.SubItems.Add(subItem);

                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = file.getAttrs().isDir() ? "文件夹" : file.getAttrs().isLink() ? "快捷方式" : getFileExt(file.getFilename());
                                    item.SubItems.Add(subItem);

                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = file.getAttrs().getMtimeString();
                                    item.SubItems.Add(subItem);

                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = file.getAttrs().getPermissionsString();
                                    item.SubItems.Add(subItem);

                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = getFileOwner(file.getLongname());
                                    item.SubItems.Add(subItem);

                                    item.ImageIndex = file.getAttrs().isDir() ? 1 : 0;
                                    if (file.getAttrs().isDir())
                                    {
                                        listView2.Items.Add(item);
                                    }
                                    else
                                    {
                                        itemList.Add(item);
                                    }
                                }
                                else
                                {
                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    subItem      = new ListViewItem.ListViewSubItem();
                                    subItem.Text = "";
                                    item.SubItems.Add(subItem);
                                    item.ImageIndex = 1;
                                    listView2.Items.Add(item);
                                }
                            }
                        }
                        foreach (ListViewItem item2 in itemList)
                        {
                            listView2.Items.Add(item2);
                        }
                        if (null != result)
                        {
                            result();
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception e) {
                    logger.Error("加载数据失败:" + e.Message, e);
                    if (!success)
                    {
                        sftpForm.CloseTab(this);
                    }
                }
            });
        }
Esempio n. 5
0
        public void LoadRemoteYmls()
        {
            btn_reload.Enabled = false;
            ArrayList fileList = monitorForm.getDirFiles(remoteCfgPath);

            if (null != fileList)
            {
                if (fileList.Count > 0)
                {
                    label1.Visible = false;

                    listView1.Items.Clear();
                    ListViewItem        item = null;
                    ChannelSftp.LsEntry file = null;
                    YmlFile             yml = null;
                    string remotePath = "", localPath = "";
                    for (int i = 0; i < fileList.Count; i++)
                    {
                        object obj = fileList[i];
                        if (obj is ChannelSftp.LsEntry)
                        {
                            file = (ChannelSftp.LsEntry)obj;
                            try
                            {
                                yml            = new YmlFile();
                                yml.correct    = true;
                                yml.localName  = file.getFilename();
                                yml.localPath  = cfgDir + "/";
                                yml.remoteName = file.getFilename();
                                yml.remotePath = remoteCfgPath + "/";
                                yml.status     = YmlFileState.NoModif;

                                item            = new ListViewItem();
                                item.Text       = file.getFilename();
                                item.Tag        = yml;
                                item.ImageIndex = 1;

                                remotePath = yml.remotePath + yml.remoteName;
                                localPath  = yml.localPath + yml.localName;

                                downloadFile(remotePath, localPath);

                                listView1.Items.Add(item);
                            }
                            catch { }
                        }
                    }
                }
                else
                {
                    label1.Text    = "暂无文件";
                    label1.Visible = true;
                }
            }
            else
            {
                label1.Text    = "加载失败";
                label1.Visible = true;
            }

            btn_reload.Enabled = true;
        }