コード例 #1
0
 private void FTPClient2_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (FTPAdapter != null)
     {
         FTPAdapter.Dispose();
     }
 }
コード例 #2
0
 private void FTPDelete()
 {
     if (lvFTPList.SelectedItems.Count > 0)
     {
         FTPAdapter.DeleteFiles(lvFTPList.SelectedItems.Cast <ListViewItem>().Select(x => x.Tag as FtpItem));
         RefreshDirectory();
     }
 }
コード例 #3
0
 private void txtConsoleWrite_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         FTPAdapter.SendCommand(txtConsoleWrite.Text);
         txtConsoleWrite.Clear();
     }
 }
コード例 #4
0
 private void lvFTPList_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
 {
     if (lvFTPList.SelectedItems.Count > 0 && !e.Cancel && !string.IsNullOrEmpty(e.DisplayText))
     {
         FtpItem file = (FtpItem)lvFTPList.SelectedItems[0].Tag;
         if (file.Name != e.DisplayText)
         {
             FTPAdapter.Rename(file.FullPath, FTPHelpers.CombineURL(currentDirectory, e.DisplayText));
             RefreshDirectory();
         }
     }
 }
コード例 #5
0
        private void FTPCreateDirectory()
        {
            InputBox ib = new InputBox {
                Text = "Create directory", Question = "Please enter the name of the directory which should be created:"
            };

            ib.ShowDialog();
            this.BringToFront();
            if (ib.DialogResult == DialogResult.OK)
            {
                FTPAdapter.MakeDirectory(FTPHelpers.CombineURL(currentDirectory, ib.InputText));
                RefreshDirectory();
            }
        }
コード例 #6
0
        private void FTPDownload(bool openDirectory)
        {
            if (lvFTPList.SelectedItems.Count > 0)
            {
                FtpItem checkDirectory = lvFTPList.SelectedItems[0].Tag as FtpItem;

                if (openDirectory && checkDirectory != null)
                {
                    if (checkDirectory.ItemType == FtpItemType.Unknown && checkDirectory.Name == "..")
                    {
                        FTPNavigateBack();
                        return;
                    }
                    else if (checkDirectory.ItemType == FtpItemType.Directory)
                    {
                        LoadDirectory(checkDirectory.FullPath);
                        return;
                    }
                }

                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.RootFolder = Environment.SpecialFolder.Desktop;

                if (fbd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(fbd.SelectedPath))
                {
                    FtpItemCollection list = new FtpItemCollection();
                    foreach (ListViewItem lvi in lvFTPList.SelectedItems)
                    {
                        FtpItem file = lvi.Tag as FtpItem;
                        if (file != null)
                        {
                            list.Add(file);
                        }
                    }

                    FTPAdapter.DownloadFiles(list, fbd.SelectedPath);
                }
            }
        }
コード例 #7
0
        private void sBwFetchlist()
        {
            if (Engine.ConfigUploaders.FTPAccountList2 != null)
            {
                mAcc = Engine.ConfigUploaders.FTPAccountList2[Engine.ConfigUploaders.FTPSelectedImage];
            }

            bwRemoteViewer.ReportProgress((int)RemoteViewerTask.ProgressType.UPDATE_STATUS_BAR_TEXT,
                                          string.Format("Fetching files from {0}", mAcc.Name));

            if (mAcc != null && !string.IsNullOrEmpty(mAcc.Host))
            {
                FTPOptions fopt = new FTPOptions();
                fopt.Account       = mAcc;
                fopt.ProxySettings = Adapter.CheckProxySettings().GetWebProxy;
                mFTP = new FTPAdapter(fopt);
                List <string> files = FetchList();
                if (files.Count > 0)
                {
                    sBwViewFile(files[0]);
                }
            }
        }
コード例 #8
0
 private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     FTPAdapter.Disconnect();
     lvFTPList.Items.Clear();
 }
コード例 #9
0
        private void lvFTPList_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(string[])))
            {
                Point        point = lvFTPList.PointToClient(new Point(e.X, e.Y));
                ListViewItem lvi   = lvFTPList.GetItemAt(point.X, point.Y);
                if (lvi != null && e.AllowedEffect == DragDropEffects.Move)
                {
                    if (tempSelected != null && tempSelected != lvi)
                    {
                        tempSelected.Selected = false;
                    }

                    FtpItem file = lvi.Tag as FtpItem;
                    if (file != null && file.ItemType == FtpItemType.Directory)
                    {
                        string[] filenames = e.Data.GetData(typeof(string[])) as string[];
                        if (filenames != null)
                        {
                            int renameCount = 0;
                            foreach (string filename in filenames)
                            {
                                if (file.Name != filename)
                                {
                                    string path     = FTPHelpers.CombineURL(currentDirectory, filename);
                                    string movePath = string.Empty;
                                    if (file.ItemType == FtpItemType.Unknown)
                                    {
                                        if (file.Name == ".")
                                        {
                                            movePath = FTPHelpers.AddSlash(filename, FTPHelpers.SlashType.Prefix, 2);
                                        }
                                        else if (file.Name == "..")
                                        {
                                            movePath = FTPHelpers.AddSlash(filename, FTPHelpers.SlashType.Prefix);
                                        }
                                    }
                                    else
                                    {
                                        movePath = FTPHelpers.CombineURL(file.FullPath, filename);
                                    }

                                    if (!string.IsNullOrEmpty(movePath))
                                    {
                                        FTPAdapter.Rename(path, movePath);
                                        renameCount++;
                                    }
                                }
                            }

                            if (renameCount > 0)
                            {
                                RefreshDirectory();
                            }
                        }
                    }
                }

                tempSelected = null;
            }
            else if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (files != null)
                {
                    FTPAdapter.UploadFiles(files, currentDirectory);
                    RefreshDirectory();
                }
            }
        }
コード例 #10
0
        private void LoadDirectory(string path)
        {
            currentDirectory = path;
            FillDirectories(currentDirectory);

            List <FtpItem> list = FTPAdapter.GetDirList(currentDirectory).
                                  OrderBy(x => x.ItemType != FtpItemType.Directory).ThenBy(x => x.Name).ToList();

            list.Insert(0, new FtpItem("..", DateTime.Now, 0, null, null, FtpItemType.Unknown, null));

            lvFTPList.Items.Clear();
            lvFTPList.SmallImageList = new ImageList {
                ColorDepth = ColorDepth.Depth32Bit
            };

            foreach (FtpItem file in list)
            {
                if (file.ItemType == FtpItemType.Directory && (file.Name == "." || file.Name == ".."))
                {
                    continue;
                }

                ListViewItem lvi = new ListViewItem(file.Name);

                lvi.Tag = file;

                if (file.ItemType != FtpItemType.Unknown)
                {
                    if (file.ItemType == FtpItemType.File)
                    {
                        lvi.SubItems.Add(file.Size.ToString("N0"));
                    }
                    else
                    {
                        lvi.SubItems.Add(string.Empty);
                    }

                    lvi.SubItems.Add(IconReader.GetDisplayName(file.Name, file.ItemType == FtpItemType.Directory));
                    lvi.SubItems.Add(file.Modified.ToLocalTime().ToString());
                    lvi.SubItems.Add(file.Attributes);
                }

                string ext;
                if (file.ItemType == FtpItemType.Directory || file.ItemType == FtpItemType.Unknown)
                {
                    ext = "Directory";
                }
                else if (Path.HasExtension(file.Name))
                {
                    ext = Path.GetExtension(file.Name);
                }
                else
                {
                    ext = "File";
                }

                if (!lvFTPList.SmallImageList.Images.Keys.Contains(ext))
                {
                    Icon icon;
                    if (ext == "Directory")
                    {
                        icon = IconReader.GetFolderIcon(IconReader.IconSize.Small, IconReader.FolderType.Closed);
                    }
                    else
                    {
                        icon = IconReader.GetFileIcon(ext, IconReader.IconSize.Small, false);
                    }

                    if (icon != null)
                    {
                        lvFTPList.SmallImageList.Images.Add(ext, icon.ToBitmap());
                    }
                }

                if (lvFTPList.SmallImageList.Images.Keys.Contains(ext))
                {
                    lvi.ImageKey = ext;
                }

                lvFTPList.Items.Add(lvi);
            }

            CheckFiles(false);
        }