FTP client works now

This commit is contained in:
Jaex 2014-05-25 07:39:13 +03:00
parent 568b8ab627
commit 101346d86c
6 changed files with 146 additions and 152 deletions

View file

@ -557,7 +557,7 @@ public static void OpenFTPClient()
if (Program.UploadersConfig != null && Program.UploadersConfig.FTPAccountList.IsValidIndex(Program.UploadersConfig.FTPSelectedImage))
{
FTPAccount account = Program.UploadersConfig.FTPAccountList[Program.UploadersConfig.FTPSelectedImage];
//new FTPClientForm(account).Show();
new FTPClientForm(account).Show();
}
}
}

View file

@ -1,6 +1,6 @@
namespace UploadersLib
{
/*partial class FTPClientForm
partial class FTPClientForm
{
/// <summary>
/// Required designer variable.
@ -50,12 +50,6 @@ private void InitializeComponent()
this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.lblStatus = new System.Windows.Forms.ToolStripStatusLabel();
this.lvFTPList = new UploadersLib.ListViewEx();
this.chFilename = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chFilesize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chFiletype = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chLastModified = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chPermissions = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.tcFTP = new System.Windows.Forms.TabControl();
this.tpMain = new System.Windows.Forms.TabPage();
this.tpAccount = new System.Windows.Forms.TabPage();
@ -64,7 +58,13 @@ private void InitializeComponent()
this.scConsole = new System.Windows.Forms.SplitContainer();
this.rtbConsole = new System.Windows.Forms.RichTextBox();
this.txtConsoleWrite = new System.Windows.Forms.TextBox();
this.lvFTPList = new UploadersLib.ListViewEx();
this.chFilename = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chFilesize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chFiletype = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.chLastModified = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.cmsRightClickMenu.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
@ -77,6 +77,7 @@ private void InitializeComponent()
this.tpMain.SuspendLayout();
this.tpAccount.SuspendLayout();
this.tpConsole.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.scConsole)).BeginInit();
this.scConsole.Panel1.SuspendLayout();
this.scConsole.Panel2.SuspendLayout();
this.scConsole.SuspendLayout();
@ -281,61 +282,6 @@ private void InitializeComponent()
this.lblStatus.Size = new System.Drawing.Size(38, 17);
this.lblStatus.Text = "status";
//
// lvFTPList
//
this.lvFTPList.AllowColumnReorder = true;
this.lvFTPList.AllowDrop = true;
this.lvFTPList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chFilename,
this.chFilesize,
this.chFiletype,
this.chLastModified,
this.chPermissions});
this.lvFTPList.ContextMenuStrip = this.cmsRightClickMenu;
this.lvFTPList.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvFTPList.DoubleClickActivation = false;
this.lvFTPList.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lvFTPList.FullRowSelect = true;
this.lvFTPList.GridLines = true;
this.lvFTPList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lvFTPList.HideSelection = false;
this.lvFTPList.Location = new System.Drawing.Point(0, 0);
this.lvFTPList.Name = "lvFTPList";
this.lvFTPList.Size = new System.Drawing.Size(952, 483);
this.lvFTPList.TabIndex = 0;
this.lvFTPList.UseCompatibleStateImageBehavior = false;
this.lvFTPList.View = System.Windows.Forms.View.Details;
this.lvFTPList.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.lvFTPList_ItemDrag);
this.lvFTPList.SelectedIndexChanged += new System.EventHandler(this.lvFTPList_SelectedIndexChanged);
this.lvFTPList.DragDrop += new System.Windows.Forms.DragEventHandler(this.lvFTPList_DragDrop);
this.lvFTPList.DragOver += new System.Windows.Forms.DragEventHandler(this.lvFTPList_DragOver);
this.lvFTPList.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lvFTPList_MouseDoubleClick);
//
// chFilename
//
this.chFilename.Text = "Filename";
this.chFilename.Width = 350;
//
// chFilesize
//
this.chFilesize.Text = "Filesize";
this.chFilesize.Width = 100;
//
// chFiletype
//
this.chFiletype.Text = "Filetype";
this.chFiletype.Width = 200;
//
// chLastModified
//
this.chLastModified.Text = "Last modified";
this.chLastModified.Width = 150;
//
// chPermissions
//
this.chPermissions.Text = "Permissions";
this.chPermissions.Width = 100;
//
// tcFTP
//
this.tcFTP.Controls.Add(this.tpMain);
@ -437,6 +383,55 @@ private void InitializeComponent()
this.txtConsoleWrite.TabIndex = 0;
this.txtConsoleWrite.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtConsoleWrite_KeyDown);
//
// lvFTPList
//
this.lvFTPList.AllowColumnReorder = true;
this.lvFTPList.AllowDrop = true;
this.lvFTPList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.chFilename,
this.chFilesize,
this.chFiletype,
this.chLastModified});
this.lvFTPList.ContextMenuStrip = this.cmsRightClickMenu;
this.lvFTPList.Dock = System.Windows.Forms.DockStyle.Fill;
this.lvFTPList.DoubleClickActivation = false;
this.lvFTPList.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lvFTPList.FullRowSelect = true;
this.lvFTPList.GridLines = true;
this.lvFTPList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lvFTPList.HideSelection = false;
this.lvFTPList.Location = new System.Drawing.Point(0, 0);
this.lvFTPList.Name = "lvFTPList";
this.lvFTPList.Size = new System.Drawing.Size(952, 483);
this.lvFTPList.TabIndex = 0;
this.lvFTPList.UseCompatibleStateImageBehavior = false;
this.lvFTPList.View = System.Windows.Forms.View.Details;
this.lvFTPList.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.lvFTPList_ItemDrag);
this.lvFTPList.SelectedIndexChanged += new System.EventHandler(this.lvFTPList_SelectedIndexChanged);
this.lvFTPList.DragDrop += new System.Windows.Forms.DragEventHandler(this.lvFTPList_DragDrop);
this.lvFTPList.DragOver += new System.Windows.Forms.DragEventHandler(this.lvFTPList_DragOver);
this.lvFTPList.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lvFTPList_MouseDoubleClick);
//
// chFilename
//
this.chFilename.Text = "Filename";
this.chFilename.Width = 493;
//
// chFilesize
//
this.chFilesize.Text = "Filesize";
this.chFilesize.Width = 100;
//
// chFiletype
//
this.chFiletype.Text = "Filetype";
this.chFiletype.Width = 200;
//
// chLastModified
//
this.chLastModified.Text = "Last modified";
this.chLastModified.Width = 150;
//
// FTPClientForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -446,12 +441,14 @@ private void InitializeComponent()
this.Controls.Add(this.txtRename);
this.Name = "FTPClientForm";
this.Padding = new System.Windows.Forms.Padding(3);
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FTP client";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FTPClient2_FormClosing);
this.Resize += new System.EventHandler(this.FTPClient_Resize);
this.cmsRightClickMenu.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.pConnecting.ResumeLayout(false);
this.toolStripContainer1.BottomToolStripPanel.ResumeLayout(false);
@ -468,6 +465,7 @@ private void InitializeComponent()
this.scConsole.Panel1.ResumeLayout(false);
this.scConsole.Panel2.ResumeLayout(false);
this.scConsole.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.scConsole)).EndInit();
this.scConsole.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -481,7 +479,6 @@ private void InitializeComponent()
private System.Windows.Forms.ColumnHeader chFilesize;
private System.Windows.Forms.ColumnHeader chFiletype;
private System.Windows.Forms.ColumnHeader chLastModified;
private System.Windows.Forms.ColumnHeader chPermissions;
private System.Windows.Forms.ContextMenuStrip cmsRightClickMenu;
private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem renameToolStripMenuItem;
@ -511,5 +508,5 @@ private void InitializeComponent()
private System.Windows.Forms.RichTextBox rtbConsole;
private System.Windows.Forms.SplitContainer scConsole;
private System.Windows.Forms.TextBox txtConsoleWrite;
}*/
}
}

View file

@ -30,16 +30,17 @@ You should have received a copy of the GNU General Public License
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.FtpClient;
using System.Windows.Forms;
using UploadersLib.FileUploaders;
namespace UploadersLib
{
/*public partial class FTPClientForm : Form
public partial class FTPClientForm : Form
{
private const string Root = "/";
public FTP FTPAdapter { get; set; }
public FTP Client { get; set; }
public FTPAccount Account { get; set; }
private string currentDirectory;
@ -55,16 +56,22 @@ public FTPClientForm(FTPAccount account)
Account = account;
FTPAdapter = new FTP(account);
FTPAdapter.client.ClientRequest += Client_ClientRequest;
FTPAdapter.client.ServerResponse += Client_ServerResponse;
FTPAdapter.client.OpenAsyncCompleted += Client_OpenAsyncCompleted;
Client = new FTP(account);
pgAccount.SelectedObject = FTPAdapter.Account;
Text = "FTP Client - " + account.Name;
pgAccount.SelectedObject = Client.Account;
Text = "ShareX FTP client - " + account.Name;
lblConnecting.Text = "Connecting to " + account.FTPAddress;
FTPAdapter.client.OpenAsync(account.Username, account.Password);
TaskEx.Run(() =>
{
Client.Connect();
},
() =>
{
pConnecting.Visible = false;
Refresh();
RefreshDirectory();
});
}
#region Methods
@ -101,17 +108,19 @@ 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<FtpListItem> list = Client.GetListing(currentDirectory).OrderBy(x => x.Type != FtpFileSystemObjectType.Directory).ThenBy(x => x.Name).ToList();
list.Insert(0, new FtpItem("..", DateTime.Now, 0, null, null, FtpItemType.Unknown, null));
if (currentDirectory != Root)
{
list.Insert(0, new FtpListItem { FullName = "..", Type = FtpFileSystemObjectType.Link });
}
lvFTPList.Items.Clear();
lvFTPList.SmallImageList = new ImageList { ColorDepth = ColorDepth.Depth32Bit };
foreach (FtpItem file in list)
foreach (FtpListItem file in list)
{
if (file.ItemType == FtpItemType.Directory && (file.Name == "." || file.Name == ".."))
if (file.Type == FtpFileSystemObjectType.Directory && (file.Name == "." || file.Name == ".."))
{
continue;
}
@ -120,9 +129,9 @@ private void LoadDirectory(string path)
lvi.Tag = file;
if (file.ItemType != FtpItemType.Unknown)
if (file.Type != FtpFileSystemObjectType.Link)
{
if (file.ItemType == FtpItemType.File)
if (file.Type == FtpFileSystemObjectType.File)
{
lvi.SubItems.Add(file.Size.ToString("N0"));
}
@ -131,13 +140,12 @@ private void LoadDirectory(string path)
lvi.SubItems.Add(string.Empty);
}
lvi.SubItems.Add(IconReader.GetDisplayName(file.Name, file.ItemType == FtpItemType.Directory));
lvi.SubItems.Add(IconReader.GetDisplayName(file.Name, file.Type == FtpFileSystemObjectType.Directory));
lvi.SubItems.Add(file.Modified.ToLocalTime().ToString());
lvi.SubItems.Add(file.Attributes);
}
string ext;
if (file.ItemType == FtpItemType.Directory || file.ItemType == FtpItemType.Unknown)
if (file.Type == FtpFileSystemObjectType.Directory || file.Type == FtpFileSystemObjectType.Link)
{
ext = "Directory";
}
@ -192,12 +200,12 @@ private void CheckFiles(bool selected)
list = lvFTPList.Items.Cast<ListViewItem>().ToArray();
}
List<FtpItem> items = new List<FtpItem>();
FtpItem item;
List<FtpListItem> items = new List<FtpListItem>();
FtpListItem item;
foreach (ListViewItem lvi in list)
{
item = lvi.Tag as FtpItem;
item = lvi.Tag as FtpListItem;
if (item != null)
{
@ -206,33 +214,32 @@ private void CheckFiles(bool selected)
}
string isSelected = selected ? "Selected " : string.Empty;
int filesCount = items.Count(x => x.ItemType == FtpItemType.File);
int filesCount = items.Count(x => x.Type == FtpFileSystemObjectType.File);
string file = filesCount > 1 ? "files" : "file";
int directoriesCount = items.Count(x => x.ItemType == FtpItemType.Directory);
int directoriesCount = items.Count(x => x.Type == FtpFileSystemObjectType.Directory);
string directory = directoriesCount > 1 ? "directories" : "directory";
string totalSize = items.Where(x => x.ItemType == FtpItemType.File).Sum(x => x.Size).ToString("N0");
string totalSize = items.Where(x => x.Type == FtpFileSystemObjectType.File).Sum(x => x.Size).ToString("N0");
lblStatus.Text = string.Format("{0}{1} {2} and {3} {4}. Total size: {5} bytes",
isSelected, filesCount, file, directoriesCount, directory, totalSize);
lblStatus.Text = string.Format("{0}{1} {2} and {3} {4}. Total size: {5} bytes", isSelected, filesCount, file, directoriesCount, directory, totalSize);
}
private void FTPDownload(bool openDirectory)
{
if (lvFTPList.SelectedItems.Count > 0)
{
FtpItem checkDirectory = lvFTPList.SelectedItems[0].Tag as FtpItem;
FtpListItem checkDirectory = lvFTPList.SelectedItems[0].Tag as FtpListItem;
if (openDirectory && checkDirectory != null)
{
if (checkDirectory.ItemType == FtpItemType.Unknown && checkDirectory.Name == "..")
if (checkDirectory.Type == FtpFileSystemObjectType.Link && checkDirectory.Name == "..")
{
FTPNavigateBack();
return;
}
if (checkDirectory.ItemType == FtpItemType.Directory)
if (checkDirectory.Type == FtpFileSystemObjectType.Directory)
{
LoadDirectory(checkDirectory.FullPath);
LoadDirectory(checkDirectory.FullName);
return;
}
}
@ -242,17 +249,17 @@ private void FTPDownload(bool openDirectory)
if (fbd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(fbd.SelectedPath))
{
FtpItemCollection list = new FtpItemCollection();
List<FtpListItem> list = new List<FtpListItem>();
foreach (ListViewItem lvi in lvFTPList.SelectedItems)
{
FtpItem file = lvi.Tag as FtpItem;
FtpListItem file = lvi.Tag as FtpListItem;
if (file != null)
{
list.Add(file);
}
}
FTPAdapter.DownloadFiles(list, fbd.SelectedPath);
Client.DownloadFiles(list, fbd.SelectedPath);
}
}
}
@ -261,8 +268,8 @@ private void FTPRename()
{
if (lvFTPList.SelectedItems.Count > 0)
{
FtpItem file = lvFTPList.SelectedItems[0].Tag as FtpItem;
if (file != null && file.ItemType != FtpItemType.Unknown)
FtpListItem file = lvFTPList.SelectedItems[0].Tag as FtpListItem;
if (file != null && file.Type != FtpFileSystemObjectType.Link)
{
lvFTPList.StartEditing(txtRename, lvFTPList.SelectedItems[0], 0);
int offset = 23;
@ -276,7 +283,7 @@ private void FTPDelete()
{
if (lvFTPList.SelectedItems.Count > 0)
{
FTPAdapter.DeleteFiles(lvFTPList.SelectedItems.Cast<ListViewItem>().Select(x => x.Tag as FtpItem));
Client.DeleteFiles(lvFTPList.SelectedItems.Cast<ListViewItem>().Select(x => x.Tag as FtpListItem));
RefreshDirectory();
}
}
@ -289,7 +296,7 @@ private void FTPCreateDirectory()
BringToFront();
if (ib.DialogResult == DialogResult.OK)
{
FTPAdapter.MakeDirectory(Helpers.CombineURL(currentDirectory, ib.InputText));
Client.MakeDirectory(Helpers.CombineURL(currentDirectory, ib.InputText));
RefreshDirectory();
}
}
@ -352,7 +359,7 @@ private void lvFTPList_ItemDrag(object sender, ItemDragEventArgs e)
List<string> filenames = new List<string>();
foreach (ListViewItem lvi in lvFTPList.SelectedItems)
{
FtpItem file = lvi.Tag as FtpItem;
FtpListItem file = lvi.Tag as FtpListItem;
if (file != null && !string.IsNullOrEmpty(file.Name))
{
filenames.Add(file.Name);
@ -379,8 +386,8 @@ private void lvFTPList_DragOver(object sender, DragEventArgs e)
tempSelected.Selected = false;
}
FtpItem file = lvi.Tag as FtpItem;
if (file != null && file.ItemType == FtpItemType.Directory)
FtpListItem file = lvi.Tag as FtpListItem;
if (file != null && file.Type == FtpFileSystemObjectType.Directory)
{
lvi.Selected = true;
tempSelected = lvi;
@ -415,8 +422,8 @@ private void lvFTPList_DragDrop(object sender, DragEventArgs e)
tempSelected.Selected = false;
}
FtpItem file = lvi.Tag as FtpItem;
if (file != null && file.ItemType == FtpItemType.Directory)
FtpListItem file = lvi.Tag as FtpListItem;
if (file != null && file.Type == FtpFileSystemObjectType.Directory)
{
string[] filenames = e.Data.GetData(typeof(string[])) as string[];
if (filenames != null)
@ -428,7 +435,7 @@ private void lvFTPList_DragDrop(object sender, DragEventArgs e)
{
string path = Helpers.CombineURL(currentDirectory, filename);
string movePath = string.Empty;
if (file.ItemType == FtpItemType.Unknown)
if (file.Type == FtpFileSystemObjectType.Link)
{
if (file.Name == ".")
{
@ -441,12 +448,12 @@ private void lvFTPList_DragDrop(object sender, DragEventArgs e)
}
else
{
movePath = Helpers.CombineURL(file.FullPath, filename);
movePath = Helpers.CombineURL(file.FullName, filename);
}
if (!string.IsNullOrEmpty(movePath))
{
FTPAdapter.Rename(path, movePath);
Client.Rename(path, movePath);
renameCount++;
}
}
@ -467,7 +474,7 @@ private void lvFTPList_DragDrop(object sender, DragEventArgs e)
string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
if (files != null)
{
FTPAdapter.UploadFiles(files, currentDirectory);
Client.UploadFiles(files, currentDirectory);
RefreshDirectory();
}
}
@ -477,10 +484,10 @@ private void lvFTPList_SubItemEndEditing(object sender, SubItemEndEditingEventAr
{
if (lvFTPList.SelectedItems.Count > 0 && !e.Cancel && !string.IsNullOrEmpty(e.DisplayText))
{
FtpItem file = (FtpItem)lvFTPList.SelectedItems[0].Tag;
FtpListItem file = (FtpListItem)lvFTPList.SelectedItems[0].Tag;
if (file.Name != e.DisplayText)
{
FTPAdapter.Rename(file.FullPath, Helpers.CombineURL(currentDirectory, e.DisplayText));
Client.Rename(file.FullName, Helpers.CombineURL(currentDirectory, e.DisplayText));
RefreshDirectory();
}
}
@ -492,11 +499,11 @@ private void lvFTPList_SelectedIndexChanged(object sender, EventArgs e)
if (lvFTPList.SelectedItems.Count > 0)
{
FtpItem file = lvFTPList.SelectedItems[0].Tag as FtpItem;
FtpListItem file = lvFTPList.SelectedItems[0].Tag as FtpListItem;
if (file != null)
{
enabled = file.ItemType != FtpItemType.Unknown;
enabled = file.Type != FtpFileSystemObjectType.Link;
}
}
@ -530,10 +537,10 @@ private void copyURLsToClipboardToolStripMenuItem_Click(object sender, EventArgs
foreach (ListViewItem lvi in lvFTPList.SelectedItems)
{
FtpItem file = lvi.Tag as FtpItem;
if (file != null && file.ItemType == FtpItemType.File)
FtpListItem file = lvi.Tag as FtpListItem;
if (file != null && file.Type == FtpFileSystemObjectType.File)
{
path = Helpers.CombineURL(Account.HttpHomePath, file.FullPath);
path = Helpers.CombineURL(Account.HttpHomePath, file.FullName);
list.Add(path);
}
}
@ -550,10 +557,10 @@ private void openURLToolStripMenuItem_Click(object sender, EventArgs e)
{
if (lvFTPList.SelectedItems.Count > 0)
{
FtpItem file = lvFTPList.SelectedItems[0].Tag as FtpItem;
if (file != null && file.ItemType == FtpItemType.File)
FtpListItem file = lvFTPList.SelectedItems[0].Tag as FtpListItem;
if (file != null && file.Type == FtpFileSystemObjectType.File)
{
TaskEx.Run(() => Process.Start(Account.GetUriPath("@" + file.FullPath)));
TaskEx.Run(() => Process.Start(Account.GetUriPath("@" + file.FullName)));
}
}
}
@ -563,13 +570,6 @@ private void FTPClient_Resize(object sender, EventArgs e)
Refresh();
}
private void Client_OpenAsyncCompleted(object sender, OpenAsyncCompletedEventArgs e)
{
pConnecting.Visible = false;
Refresh();
RefreshDirectory();
}
private void connectToolStripMenuItem_Click(object sender, EventArgs e)
{
RefreshDirectory();
@ -577,37 +577,27 @@ private void connectToolStripMenuItem_Click(object sender, EventArgs e)
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
{
FTPAdapter.Disconnect();
Client.Disconnect();
lvFTPList.Items.Clear();
}
private void Client_ClientRequest(object sender, FtpRequestEventArgs e)
{
AddConsoleMessage(e.Request.Text, Color.Blue);
}
private void Client_ServerResponse(object sender, FtpResponseEventArgs e)
{
AddConsoleMessage(e.Response.RawText, Color.DarkGreen);
}
private void txtConsoleWrite_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
FTPAdapter.SendCommand(txtConsoleWrite.Text);
Client.SendCommand(txtConsoleWrite.Text);
txtConsoleWrite.Clear();
}
}
private void FTPClient2_FormClosing(object sender, FormClosingEventArgs e)
{
if (FTPAdapter != null)
if (Client != null)
{
FTPAdapter.Dispose();
Client.Dispose();
}
}
#endregion Events
}*/
}
}

View file

@ -112,18 +112,18 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="cmsRightClickMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="cmsRightClickMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>133, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>51</value>
</metadata>
</root>

View file

@ -263,7 +263,7 @@ public void DownloadFiles(IEnumerable<FtpListItem> files, string localPath, bool
{
if (recursive && file.Type == FtpFileSystemObjectType.Directory)
{
FtpListItem[] newFiles = client.GetListing(file.FullName);
FtpListItem[] newFiles = GetListing(file.FullName);
string directoryPath = Path.Combine(localPath, file.Name);
if (!Directory.Exists(directoryPath))
@ -282,6 +282,11 @@ public void DownloadFiles(IEnumerable<FtpListItem> files, string localPath, bool
}
}
public FtpListItem[] GetListing(string remotePath)
{
return client.GetListing(remotePath);
}
public bool ChangeDirectory(string remotePath, bool autoCreateDirectory = false)
{
if (Connect())
@ -385,7 +390,7 @@ public void DeleteDirectory(string remotePath)
return;
}
FtpListItem[] files = client.GetListing(remotePath);
FtpListItem[] files = GetListing(remotePath);
DeleteFiles(files);

View file

@ -111,7 +111,9 @@
<Compile Include="FileUploaders\SFTP.cs" />
<Compile Include="FileUploaders\Minus.cs" />
<Compile Include="FileUploaders\SharedFolderUploader.cs" />
<Compile Include="FTPClient\FTPClientForm.cs" />
<Compile Include="FTPClient\FTPClientForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FTPClient\FTPClientForm.Designer.cs">
<DependentUpon>FTPClientForm.cs</DependentUpon>
</Compile>