private void btnCopyToClip_Click(object sender, EventArgs e) { string str = ""; List <string> items = new List <string>(); foreach (string obj in lbFiles.SelectedItems) { items.Add(mAcc.GetUriPath(FTPHelpers.GetFileName(obj)) + Environment.NewLine); } if (cbReverse.Checked) { items.Reverse(); } str = string.Join(Environment.NewLine, items.ToArray()); if (cbAddSpace.Checked) { str = str.Insert(0, Environment.NewLine); } if (!string.IsNullOrEmpty(str)) { Clipboard.SetText(str); // ok } }
private List <string> FetchList() { List <string> result = new List <string>(); try { string[] splode, str = mFTP.ListDirectory(FTPHelpers.CombineURL(mAcc.FTPAddress, mAcc.GetSubFolderPath())); string goodFile; bwRemoteViewer.ReportProgress((int)RemoteViewerTask.ProgressType.UPDATE_PROGRESS_MAX, str.Length); for (int x = 0; x < str.Length; x++) { splode = str[x].Split(' '); goodFile = splode[splode.Length - 1]; if (goodFile.Length > 2 && goodFile.Contains(".")) { result.Add(goodFile); bwRemoteViewer.ReportProgress((int)RemoteViewerTask.ProgressType.ADD_FILE_TO_LISTBOX, goodFile); } } } catch (Exception e) { MessageBox.Show(e.Message, "ZScreen FTP"); } return(result); }
private void sBwViewFile(string file) { string localfile = FileSystem.GetTempFilePath(file); if (!File.Exists(localfile)) { bwRemoteViewer.ReportProgress((int)RemoteViewerTask.ProgressType.FETCHING_FILE, file); try { //mFTP.ChangeDir(mAcc.Path); string directory = Path.GetDirectoryName(localfile); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } mFTP.DownloadFile(FTPHelpers.CombineURL(mAcc.FTPAddress, mAcc.GetSubFolderPath(), file), localfile); } catch (System.Exception ex) { DebugHelper.WriteException(ex, "Error while viewing file in View Remote"); // bwRemoteViewer.ReportProgress((int)RemoteViewerTask.ProgressType.VIEWING_FILE, ""); } } // toDelete.Add(localfile); bwRemoteViewer.ReportProgress((int)RemoteViewerTask.ProgressType.VIEWING_FILE, localfile); }
private void btnDelete_Click(object sender, System.EventArgs e) { try { List <string> list = new List <string>(); foreach (string item in lbFiles.SelectedItems) { list.Add(item); } foreach (string obj in list) { if (!string.IsNullOrEmpty(obj)) { mFTP.DeleteFile(FTPHelpers.CombineURL(mAcc.FTPAddress, mAcc.GetSubFolderPath(), obj)); lbFiles.Items.Remove(obj); } } } catch (Exception ex) { DebugHelper.WriteException(ex, "Error while deleting file in View Remote"); MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (lbFiles.Items.Count > 0) { lbFiles.SelectedIndex = 0; } }
private string GetRemotePath(string fileName) { fileName = ZAppHelper.ReplaceIllegalChars(fileName, '_'); while (fileName.IndexOf("__") != -1) { fileName = fileName.Replace("__", "_"); } return(FTPHelpers.CombineURL(FTPAccount.GetSubFolderPath(), fileName)); }
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(); } } }
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(); } }
public List <string> CreateMultiDirectory(string path) { List <string> directoryList = new List <string>(); IEnumerable <string> paths = FTPHelpers.GetPaths(path).Select(x => x.TrimStart('/')); foreach (string directory in paths) { if (!DirectoryExists(directory)) { CreateDirectory(directory); directoryList.Add(directory); } } return(directoryList); }
private void FillDirectories(string path) { List <string> paths = FTPHelpers.GetPaths(path); paths.Insert(0, "/"); cbDirectoryList.Items.Clear(); foreach (string directory in paths) { cbDirectoryList.Items.Add(directory); } if (cbDirectoryList.Items.Count > 0) { cbDirectoryList.SelectedIndex = cbDirectoryList.Items.Count - 1; } }
public void CreateDirectory(string Path) { try { client.CreateDirectory(Path); DebugHelper.WriteLine("Created Directory: " + Path); } catch (SftpPathNotFoundException) { DebugHelper.WriteLine("Failed to create directory " + Path); DebugHelper.WriteLine("Attempting to fix..."); CreateMultipleDirectorys(FTPHelpers.GetPaths(Path)); } catch (SftpPermissionDeniedException) { } }
private void copyURLsToClipboardToolStripMenuItem_Click(object sender, EventArgs e) { string path; List <string> list = new List <string>(); foreach (ListViewItem lvi in lvFTPList.SelectedItems) { FtpItem file = lvi.Tag as FtpItem; if (file != null && file.ItemType == FtpItemType.File) { path = FTPHelpers.CombineURL(Account.GetHttpHomePath(), file.FullPath); list.Add(path); } } string clipboard = string.Join("\r\n", list.ToArray()); if (!string.IsNullOrEmpty(clipboard)) { Clipboard.SetText(clipboard); // ok } }
private void btnSave_Click(object sender, System.EventArgs e) { string dir; folderBrowseDialog.SelectedPath = Engine.ImagesDir; folderBrowseDialog.ShowNewFolderButton = true; if (folderBrowseDialog.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(dir = folderBrowseDialog.SelectedPath)) { try { foreach (string str in lbFiles.SelectedItems) { mFTP.DownloadFile(FTPHelpers.CombineURL(mAcc.FTPAddress, mAcc.GetSubFolderPath(), str), Path.Combine(dir, Path.GetFileName(str))); } } catch { MessageBox.Show("Save Failed"); } } }
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(); } } }
public static void TestFTPAccount(FTPAccount account, bool silent) { string msg = string.Empty; string sfp = account.GetSubFolderPath(); bool succ = false; switch (account.Protocol) { case FTPProtocol.SFTP: SFTP sftp = new SFTP(account); if (!sftp.IsInstantiated) { msg = "An SFTP client couldn't be instantiated, not enough information.\nCould be a missing key file."; } else { sftp.Connect(); List <string> createddirs = new List <string>(); if (!sftp.DirectoryExists(sfp)) { createddirs = sftp.CreateMultipleDirectorys(FTPHelpers.GetPaths(sfp)); } if (sftp.IsConnected) { msg = (createddirs.Count == 0) ? "Connected!" : "Conected!\nCreated folders;\n"; for (int x = 0; x <= createddirs.Count - 1; x++) { msg += createddirs[x] + "\n"; } msg += " \n\nPing results:\n " + SendPing(account.Host, 3); sftp.Disconnect(); } } break; default: using (FTP ftpClient = new FTP(account)) { try { succ = ftpClient.Test(sfp); if (succ) { msg = "Success!"; } } catch (Exception e) { if (e.Message.StartsWith("Could not change working directory to")) { try { ftpClient.MakeMultiDirectory(sfp); ftpClient.Test(sfp); msg = "Success!\nAuto created folders: " + sfp; } catch (Exception e2) { msg = e2.Message; } } else { msg = e.Message; } } } if (succ && !string.IsNullOrEmpty(msg)) { string ping = SendPing(account.Host, 3); if (!string.IsNullOrEmpty(ping)) { msg += "\n\nPing results:\n" + ping; } } break; } if (succ && silent) { DebugHelper.WriteLine(string.Format("Tested {0} sub-folder path in {1}", sfp, account.ToString())); } else if (succ) { MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } }