mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Using System.Net.FtpClient library instead Starksoft.Net.Ftp library.
This commit is contained in:
parent
9aef38f576
commit
285662f052
13 changed files with 149 additions and 262 deletions
|
@ -59,9 +59,6 @@
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Starksoft.Net.Proxy">
|
|
||||||
<HintPath>..\Lib\Starksoft.Net.Proxy.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Design" />
|
<Reference Include="System.Design" />
|
||||||
|
|
|
@ -23,7 +23,6 @@ You should have received a copy of the GNU General Public License
|
||||||
|
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using Starksoft.Net.Proxy;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -100,39 +99,6 @@ public IWebProxy GetWebProxy()
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy for FTP
|
|
||||||
public IProxyClient GetProxyClient()
|
|
||||||
{
|
|
||||||
if (IsValidProxy())
|
|
||||||
{
|
|
||||||
Starksoft.Net.Proxy.ProxyType proxyType;
|
|
||||||
|
|
||||||
switch (ProxyType)
|
|
||||||
{
|
|
||||||
case ProxyType.HTTP:
|
|
||||||
proxyType = Starksoft.Net.Proxy.ProxyType.Http;
|
|
||||||
break;
|
|
||||||
case ProxyType.SOCKS4:
|
|
||||||
proxyType = Starksoft.Net.Proxy.ProxyType.Socks4;
|
|
||||||
break;
|
|
||||||
case ProxyType.SOCKS4a:
|
|
||||||
proxyType = Starksoft.Net.Proxy.ProxyType.Socks4a;
|
|
||||||
break;
|
|
||||||
case ProxyType.SOCKS5:
|
|
||||||
proxyType = Starksoft.Net.Proxy.ProxyType.Socks5;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
proxyType = Starksoft.Net.Proxy.ProxyType.None;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProxyClientFactory proxy = new ProxyClientFactory();
|
|
||||||
return proxy.CreateProxyClient(proxyType, Host, Port, Username, Password);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WebProxy GetDefaultWebProxy()
|
private WebProxy GetDefaultWebProxy()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -557,7 +557,7 @@ public static void OpenFTPClient()
|
||||||
if (Program.UploadersConfig != null && Program.UploadersConfig.FTPAccountList.IsValidIndex(Program.UploadersConfig.FTPSelectedImage))
|
if (Program.UploadersConfig != null && Program.UploadersConfig.FTPAccountList.IsValidIndex(Program.UploadersConfig.FTPSelectedImage))
|
||||||
{
|
{
|
||||||
FTPAccount account = Program.UploadersConfig.FTPAccountList[Program.UploadersConfig.FTPSelectedImage];
|
FTPAccount account = Program.UploadersConfig.FTPAccountList[Program.UploadersConfig.FTPSelectedImage];
|
||||||
new FTPClientForm(account).Show();
|
//new FTPClientForm(account).Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -837,20 +837,21 @@ public UploadResult UploadFile(Stream stream, string fileName)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FileDestination.FTP:
|
case FileDestination.FTP:
|
||||||
int index = Info.TaskSettings.OverrideFTP ? Info.TaskSettings.FTPIndex.BetweenOrDefault(0, Program.UploadersConfig.FTPAccountList.Count - 1) : Program.UploadersConfig.GetFTPIndex(Info.DataType);
|
int index = Info.TaskSettings.OverrideFTP ? Info.TaskSettings.FTPIndex.BetweenOrDefault(0, Program.UploadersConfig.FTPAccountList.Count - 1) :
|
||||||
|
Program.UploadersConfig.GetFTPIndex(Info.DataType);
|
||||||
|
|
||||||
FTPAccount account = Program.UploadersConfig.FTPAccountList.ReturnIfValidIndex(index);
|
FTPAccount account = Program.UploadersConfig.FTPAccountList.ReturnIfValidIndex(index);
|
||||||
|
|
||||||
if (account != null)
|
if (account != null)
|
||||||
{
|
{
|
||||||
if (account.Protocol == FTPProtocol.SFTP)
|
if (account.Protocol == FTPProtocol.FTP || account.Protocol == FTPProtocol.FTPS)
|
||||||
|
{
|
||||||
|
fileUploader = new FTP(account);
|
||||||
|
}
|
||||||
|
else if (account.Protocol == FTPProtocol.SFTP)
|
||||||
{
|
{
|
||||||
fileUploader = new SFTP(account);
|
fileUploader = new SFTP(account);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
fileUploader = new FTPUploader(account);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FileDestination.SharedFolder:
|
case FileDestination.SharedFolder:
|
||||||
|
|
4
UploadersLib/FTPClient/FTPClientForm.Designer.cs
generated
4
UploadersLib/FTPClient/FTPClientForm.Designer.cs
generated
|
@ -1,6 +1,6 @@
|
||||||
namespace UploadersLib
|
namespace UploadersLib
|
||||||
{
|
{
|
||||||
partial class FTPClientForm
|
/*partial class FTPClientForm
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
|
@ -511,5 +511,5 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.RichTextBox rtbConsole;
|
private System.Windows.Forms.RichTextBox rtbConsole;
|
||||||
private System.Windows.Forms.SplitContainer scConsole;
|
private System.Windows.Forms.SplitContainer scConsole;
|
||||||
private System.Windows.Forms.TextBox txtConsoleWrite;
|
private System.Windows.Forms.TextBox txtConsoleWrite;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@ You should have received a copy of the GNU General Public License
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using HelpersLib;
|
using HelpersLib;
|
||||||
using Starksoft.Net.Ftp;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -32,10 +31,11 @@ You should have received a copy of the GNU General Public License
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using UploadersLib.FileUploaders;
|
||||||
|
|
||||||
namespace UploadersLib
|
namespace UploadersLib
|
||||||
{
|
{
|
||||||
public partial class FTPClientForm : Form
|
/*public partial class FTPClientForm : Form
|
||||||
{
|
{
|
||||||
private const string Root = "/";
|
private const string Root = "/";
|
||||||
|
|
||||||
|
@ -56,15 +56,15 @@ public FTPClientForm(FTPAccount account)
|
||||||
Account = account;
|
Account = account;
|
||||||
|
|
||||||
FTPAdapter = new FTP(account);
|
FTPAdapter = new FTP(account);
|
||||||
FTPAdapter.Client.ClientRequest += Client_ClientRequest;
|
FTPAdapter.client.ClientRequest += Client_ClientRequest;
|
||||||
FTPAdapter.Client.ServerResponse += Client_ServerResponse;
|
FTPAdapter.client.ServerResponse += Client_ServerResponse;
|
||||||
FTPAdapter.Client.OpenAsyncCompleted += Client_OpenAsyncCompleted;
|
FTPAdapter.client.OpenAsyncCompleted += Client_OpenAsyncCompleted;
|
||||||
|
|
||||||
pgAccount.SelectedObject = FTPAdapter.Account;
|
pgAccount.SelectedObject = FTPAdapter.Account;
|
||||||
Text = "FTP Client - " + account.Name;
|
Text = "FTP Client - " + account.Name;
|
||||||
lblConnecting.Text = "Connecting to " + account.FTPAddress;
|
lblConnecting.Text = "Connecting to " + account.FTPAddress;
|
||||||
|
|
||||||
FTPAdapter.Client.OpenAsync(account.Username, account.Password);
|
FTPAdapter.client.OpenAsync(account.Username, account.Password);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
@ -609,5 +609,5 @@ private void FTPClient2_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Events
|
#endregion Events
|
||||||
}
|
}*/
|
||||||
}
|
}
|
|
@ -24,123 +24,147 @@ You should have received a copy of the GNU General Public License
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using HelpersLib;
|
using HelpersLib;
|
||||||
using Starksoft.Net.Ftp;
|
|
||||||
using Starksoft.Net.Proxy;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.FtpClient;
|
||||||
|
using System.Net.Security;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UploadersLib.HelperClasses;
|
|
||||||
|
|
||||||
namespace UploadersLib
|
namespace UploadersLib.FileUploaders
|
||||||
{
|
{
|
||||||
public sealed class FTP : IDisposable
|
public sealed class FTP : FileUploader, IDisposable
|
||||||
{
|
{
|
||||||
public event Uploader.ProgressEventHandler ProgressChanged;
|
public FTPAccount Account { get; private set; }
|
||||||
|
//public bool AutoReconnect { get; set; }
|
||||||
|
|
||||||
public FTPAccount Account { get; set; }
|
private FtpClient client;
|
||||||
public FtpClient Client { get; set; }
|
|
||||||
public bool AutoReconnect { get; set; }
|
|
||||||
|
|
||||||
private ProgressManager progress;
|
public FTP(FTPAccount account)
|
||||||
|
|
||||||
public FTP(FTPAccount account, int bufferSize = 8192)
|
|
||||||
{
|
{
|
||||||
Account = account;
|
Account = account;
|
||||||
Client = new FtpClient(account.Host, account.Port);
|
|
||||||
Client.TcpBufferSize = bufferSize;
|
|
||||||
|
|
||||||
if (account.Protocol == FTPProtocol.FTP || account.FtpsSecurityProtocol == FtpSecurityProtocol.None)
|
client = new FtpClient()
|
||||||
{
|
{
|
||||||
Client.SecurityProtocol = (Starksoft.Net.Ftp.FtpSecurityProtocol)FtpSecurityProtocol.None;
|
Host = Account.Host,
|
||||||
|
Port = Account.Port,
|
||||||
|
Credentials = new NetworkCredential(Account.Username, Account.Password)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (account.IsActive)
|
||||||
|
{
|
||||||
|
client.DataConnectionType = FtpDataConnectionType.AutoActive;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Client.SecurityProtocol = (Starksoft.Net.Ftp.FtpSecurityProtocol)account.FtpsSecurityProtocol;
|
client.DataConnectionType = FtpDataConnectionType.AutoPassive;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (account.Protocol == FTPProtocol.FTPS && account.FtpsSecurityProtocol != FtpSecurityProtocol.None)
|
||||||
|
{
|
||||||
|
client.EncryptionMode = FtpEncryptionMode.Explicit;
|
||||||
|
client.DataConnectionEncryption = true;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(account.FtpsCertLocation) && File.Exists(account.FtpsCertLocation))
|
if (!string.IsNullOrEmpty(account.FtpsCertLocation) && File.Exists(account.FtpsCertLocation))
|
||||||
{
|
{
|
||||||
Client.SecurityCertificates.Add(X509Certificate.CreateFromSignedFile(account.FtpsCertLocation));
|
X509Certificate cert = X509Certificate2.CreateFromSignedFile(Account.FtpsCertLocation);
|
||||||
|
client.ClientCertificates.Add(cert);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Client.ValidateServerCertificate += (sender, e) => e.IsCertificateValid = true;
|
client.ValidateCertificate += (FtpClient control, FtpSslValidationEventArgs e) =>
|
||||||
|
{
|
||||||
|
if (e.PolicyErrors != SslPolicyErrors.None)
|
||||||
|
{
|
||||||
|
e.Accept = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Client.DataTransferMode = account.IsActive ? TransferMode.Active : TransferMode.Passive;
|
public override UploadResult Upload(Stream stream, string fileName)
|
||||||
|
|
||||||
if (ProxyInfo.Current != null)
|
|
||||||
{
|
{
|
||||||
IProxyClient proxy = ProxyInfo.Current.GetProxyClient();
|
UploadResult result = new UploadResult();
|
||||||
|
|
||||||
if (proxy != null)
|
fileName = Helpers.GetValidURL(fileName);
|
||||||
|
string path = Account.GetSubFolderPath(fileName);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Client.Proxy = proxy;
|
IsUploading = true;
|
||||||
|
UploadData(stream, path);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsUploading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stopUpload && Errors.Count == 0)
|
||||||
|
{
|
||||||
|
result.URL = Account.GetUriPath(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void StopUpload()
|
||||||
|
{
|
||||||
|
if (IsUploading && !stopUpload)
|
||||||
|
{
|
||||||
|
stopUpload = true;
|
||||||
|
Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Client.TransferProgress += OnTransferProgressChanged;
|
private string GetRemotePath(string filename)
|
||||||
Client.ConnectionClosed += Client_ConnectionClosed;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTransferProgressChanged(object sender, TransferProgressEventArgs e)
|
|
||||||
{
|
{
|
||||||
if (ProgressChanged != null)
|
filename = Helpers.GetValidURL(filename);
|
||||||
{
|
return Account.GetSubFolderPath(filename);
|
||||||
progress.UpdateProgress(e.BytesTransferred);
|
|
||||||
ProgressChanged(progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Client_ConnectionClosed(object sender, ConnectionClosedEventArgs e)
|
|
||||||
{
|
|
||||||
if (AutoReconnect)
|
|
||||||
{
|
|
||||||
Connect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Connect(string username, string password)
|
|
||||||
{
|
|
||||||
if (!Client.IsConnected && !string.IsNullOrEmpty(password))
|
|
||||||
{
|
|
||||||
Client.Open(username, password);
|
|
||||||
}
|
|
||||||
return Client.IsConnected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Connect()
|
public bool Connect()
|
||||||
{
|
{
|
||||||
return Connect(Account.Username, Account.Password);
|
if (!client.IsConnected)
|
||||||
|
{
|
||||||
|
client.Connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.IsConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
if (Client != null && Client.IsConnected)
|
if (client != null && client.IsConnected)
|
||||||
{
|
{
|
||||||
Client.Close();
|
client.Disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UploadData(Stream stream, string remotePath)
|
public void UploadData(Stream localStream, string remotePath)
|
||||||
{
|
{
|
||||||
if (Connect())
|
if (Connect())
|
||||||
{
|
{
|
||||||
progress = new ProgressManager(stream.Length);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Client.PutFile(stream, remotePath, FileAction.Create);
|
using (Stream remoteStream = client.OpenWrite(remotePath))
|
||||||
|
{
|
||||||
|
TransferData(localStream, remoteStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (e.InnerException.Message.Contains("No such file or directory"))
|
if (e.InnerException.Message.Contains("No such file or directory"))
|
||||||
{
|
{
|
||||||
MakeMultiDirectory(FTPHelpers.GetDirectoryName(remotePath));
|
MakeMultiDirectory(FTPHelpers.GetDirectoryName(remotePath));
|
||||||
Client.PutFile(stream, remotePath, FileAction.Create);
|
|
||||||
|
using (Stream remoteStream = client.OpenWrite(remotePath))
|
||||||
|
{
|
||||||
|
TransferData(localStream, remoteStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -190,6 +214,7 @@ public void UploadFiles(string[] localPaths, string remotePath)
|
||||||
if (!string.IsNullOrEmpty(file))
|
if (!string.IsNullOrEmpty(file))
|
||||||
{
|
{
|
||||||
string filename = Path.GetFileName(file);
|
string filename = Path.GetFileName(file);
|
||||||
|
|
||||||
if (File.Exists(file))
|
if (File.Exists(file))
|
||||||
{
|
{
|
||||||
UploadFile(file, Helpers.CombineURL(remotePath, filename));
|
UploadFile(file, Helpers.CombineURL(remotePath, filename));
|
||||||
|
@ -207,36 +232,39 @@ public void UploadFiles(string[] localPaths, string remotePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopUpload()
|
|
||||||
{
|
|
||||||
if (Client != null && Client.IsConnected)
|
|
||||||
{
|
|
||||||
Client.Abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DownloadFile(string remotePath, string localPath)
|
public void DownloadFile(string remotePath, string localPath)
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
Client.GetFile(remotePath, localPath, FileAction.Create);
|
|
||||||
|
using (FileStream fs = new FileStream(localPath, FileMode.Create))
|
||||||
|
{
|
||||||
|
DownloadFile(remotePath, fs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DownloadFile(string remotePath, Stream outStream)
|
public void DownloadFile(string remotePath, Stream localStream)
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
Client.GetFile(remotePath, outStream, false);
|
|
||||||
|
using (Stream remoteStream = client.OpenRead(remotePath))
|
||||||
|
{
|
||||||
|
TransferData(remoteStream, localStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DownloadFiles(IEnumerable<FtpItem> files, string localPath)
|
public void DownloadFiles(IEnumerable<FtpListItem> files, string localPath, bool recursive = true)
|
||||||
{
|
{
|
||||||
foreach (FtpItem file in files)
|
Connect();
|
||||||
|
|
||||||
|
foreach (FtpListItem file in files)
|
||||||
{
|
{
|
||||||
if (file != null && !string.IsNullOrEmpty(file.Name))
|
if (file != null && !string.IsNullOrEmpty(file.Name))
|
||||||
{
|
{
|
||||||
if (file.ItemType == FtpItemType.Directory)
|
if (recursive && file.Type == FtpFileSystemObjectType.Directory)
|
||||||
{
|
{
|
||||||
FtpItemCollection newFiles = GetDirList(file.FullPath);
|
FtpListItem[] newFiles = client.GetListing(file.FullName);
|
||||||
string directoryPath = Path.Combine(localPath, file.Name);
|
string directoryPath = Path.Combine(localPath, file.Name);
|
||||||
|
|
||||||
if (!Directory.Exists(directoryPath))
|
if (!Directory.Exists(directoryPath))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(directoryPath);
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
@ -244,20 +272,15 @@ public void DownloadFiles(IEnumerable<FtpItem> files, string localPath)
|
||||||
|
|
||||||
DownloadFiles(newFiles, directoryPath);
|
DownloadFiles(newFiles, directoryPath);
|
||||||
}
|
}
|
||||||
else if (file.ItemType == FtpItemType.File)
|
else if (file.Type == FtpFileSystemObjectType.File)
|
||||||
{
|
{
|
||||||
DownloadFile(file.FullPath, Path.Combine(localPath, file.Name));
|
string filePath = Path.Combine(localPath, file.Name);
|
||||||
|
DownloadFile(file.FullName, filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FtpItemCollection GetDirList(string remotePath)
|
|
||||||
{
|
|
||||||
Connect();
|
|
||||||
return Client.GetDirList(remotePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ChangeDirectory(string remotePath, bool autoCreateDirectory = false)
|
public bool ChangeDirectory(string remotePath, bool autoCreateDirectory = false)
|
||||||
{
|
{
|
||||||
if (Connect())
|
if (Connect())
|
||||||
|
@ -266,7 +289,7 @@ public bool ChangeDirectory(string remotePath, bool autoCreateDirectory = false)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Client.ChangeDirectory(remotePath);
|
client.SetWorkingDirectory(remotePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -274,7 +297,7 @@ public bool ChangeDirectory(string remotePath, bool autoCreateDirectory = false)
|
||||||
if (autoCreateDirectory && e.Message.StartsWith("Could not change working directory to"))
|
if (autoCreateDirectory && e.Message.StartsWith("Could not change working directory to"))
|
||||||
{
|
{
|
||||||
MakeMultiDirectory(remotePath);
|
MakeMultiDirectory(remotePath);
|
||||||
Client.ChangeDirectory(remotePath);
|
client.SetWorkingDirectory(remotePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +314,7 @@ public bool MakeDirectory(string remotePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Client.MakeDirectory(remotePath);
|
client.CreateDirectory(remotePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -319,28 +342,28 @@ public void MakeMultiDirectory(string remotePath)
|
||||||
public void Rename(string fromRemotePath, string toRemotePath)
|
public void Rename(string fromRemotePath, string toRemotePath)
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
Client.Rename(fromRemotePath, toRemotePath);
|
client.Rename(fromRemotePath, toRemotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFile(string remotePath)
|
public void DeleteFile(string remotePath)
|
||||||
{
|
{
|
||||||
Connect();
|
Connect();
|
||||||
Client.DeleteFile(remotePath);
|
client.DeleteFile(remotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteFiles(IEnumerable<FtpItem> files)
|
public void DeleteFiles(IEnumerable<FtpListItem> files)
|
||||||
{
|
{
|
||||||
foreach (FtpItem file in files)
|
foreach (FtpListItem file in files)
|
||||||
{
|
{
|
||||||
if (file != null && !string.IsNullOrEmpty(file.Name))
|
if (file != null && !string.IsNullOrEmpty(file.Name))
|
||||||
{
|
{
|
||||||
if (file.ItemType == FtpItemType.Directory)
|
if (file.Type == FtpFileSystemObjectType.Directory)
|
||||||
{
|
{
|
||||||
DeleteDirectory(file.FullPath);
|
DeleteDirectory(file.FullName);
|
||||||
}
|
}
|
||||||
else if (file.ItemType == FtpItemType.File)
|
else if (file.Type == FtpFileSystemObjectType.File)
|
||||||
{
|
{
|
||||||
DeleteFile(file.FullPath);
|
DeleteFile(file.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,21 +379,11 @@ public void DeleteDirectory(string remotePath)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FtpItemCollection files = GetDirList(remotePath);
|
FtpListItem[] files = client.GetListing(remotePath);
|
||||||
|
|
||||||
foreach (FtpItem file in files)
|
DeleteFiles(files);
|
||||||
{
|
|
||||||
if (file.ItemType == FtpItemType.Directory)
|
|
||||||
{
|
|
||||||
DeleteDirectory(file.FullPath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DeleteFile(file.FullPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Client.DeleteDirectory(remotePath);
|
client.DeleteDirectory(remotePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SendCommand(string command)
|
public bool SendCommand(string command)
|
||||||
|
@ -379,7 +392,7 @@ public bool SendCommand(string command)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Client.Quote(command);
|
client.Execute(command);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
@ -389,9 +402,12 @@ public bool SendCommand(string command)
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (client != null)
|
||||||
{
|
{
|
||||||
Disconnect();
|
Disconnect();
|
||||||
Client.Dispose();
|
client.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,88 +0,0 @@
|
||||||
#region License Information (GPL v3)
|
|
||||||
|
|
||||||
/*
|
|
||||||
ShareX - A program that allows you to take screenshots and share any file type
|
|
||||||
Copyright (C) 2007-2014 ShareX Developers
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License
|
|
||||||
as published by the Free Software Foundation; either version 2
|
|
||||||
of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
|
|
||||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endregion License Information (GPL v3)
|
|
||||||
|
|
||||||
using HelpersLib;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace UploadersLib.FileUploaders
|
|
||||||
{
|
|
||||||
public class FTPUploader : FileUploader
|
|
||||||
{
|
|
||||||
public FTPAccount Account { get; private set; }
|
|
||||||
|
|
||||||
private FTP ftpClient;
|
|
||||||
|
|
||||||
public FTPUploader(FTPAccount account)
|
|
||||||
{
|
|
||||||
Account = account;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override UploadResult Upload(Stream stream, string fileName)
|
|
||||||
{
|
|
||||||
UploadResult result = new UploadResult();
|
|
||||||
|
|
||||||
fileName = Helpers.GetValidURL(fileName);
|
|
||||||
string path = Account.GetSubFolderPath(fileName);
|
|
||||||
|
|
||||||
using (ftpClient = new FTP(Account, BufferSize))
|
|
||||||
{
|
|
||||||
ftpClient.ProgressChanged += OnProgressChanged;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IsUploading = true;
|
|
||||||
ftpClient.UploadData(stream, path);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
IsUploading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stopUpload && Errors.Count == 0)
|
|
||||||
{
|
|
||||||
result.URL = Account.GetUriPath(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void StopUpload()
|
|
||||||
{
|
|
||||||
if (IsUploading && !stopUpload && ftpClient != null)
|
|
||||||
{
|
|
||||||
stopUpload = true;
|
|
||||||
|
|
||||||
TaskEx.Run(() => ftpClient.StopUpload());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected string GetRemotePath(string filename)
|
|
||||||
{
|
|
||||||
filename = Helpers.GetValidURL(filename);
|
|
||||||
return Account.GetSubFolderPath(filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -895,7 +895,7 @@ private void FTPOpenClient()
|
||||||
{
|
{
|
||||||
if (CheckFTPAccounts())
|
if (CheckFTPAccounts())
|
||||||
{
|
{
|
||||||
new FTPClientForm(Config.FTPAccountList[ucFTPAccounts.lbAccounts.SelectedIndex]).Show();
|
//new FTPClientForm(Config.FTPAccountList[ucFTPAccounts.lbAccounts.SelectedIndex]).Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,16 +80,13 @@
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\packages\SSH.NET.2014.4.6-beta1\lib\net40\Renci.SshNet.dll</HintPath>
|
<HintPath>..\packages\SSH.NET.2014.4.6-beta1\lib\net40\Renci.SshNet.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Starksoft.Net.Ftp">
|
|
||||||
<HintPath>..\Lib\Starksoft.Net.Ftp.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Starksoft.Net.Proxy">
|
|
||||||
<HintPath>..\Lib\Starksoft.Net.Proxy.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Design" />
|
<Reference Include="System.Design" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Net.FtpClient">
|
||||||
|
<HintPath>..\packages\System.Net.FtpClient.1.0.5200.21177\lib\net40\System.Net.FtpClient.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Runtime.Serialization" />
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
<Reference Include="System.ServiceModel.Web" />
|
<Reference Include="System.ServiceModel.Web" />
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
|
@ -114,9 +111,7 @@
|
||||||
<Compile Include="FileUploaders\SFTP.cs" />
|
<Compile Include="FileUploaders\SFTP.cs" />
|
||||||
<Compile Include="FileUploaders\Minus.cs" />
|
<Compile Include="FileUploaders\Minus.cs" />
|
||||||
<Compile Include="FileUploaders\SharedFolderUploader.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">
|
<Compile Include="FTPClient\FTPClientForm.Designer.cs">
|
||||||
<DependentUpon>FTPClientForm.cs</DependentUpon>
|
<DependentUpon>FTPClientForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -261,7 +256,6 @@
|
||||||
<Compile Include="ImageUploader.cs" />
|
<Compile Include="ImageUploader.cs" />
|
||||||
<Compile Include="FileUploaders\CustomFileUploader.cs" />
|
<Compile Include="FileUploaders\CustomFileUploader.cs" />
|
||||||
<Compile Include="ImageUploaders\FlickrUploader.cs" />
|
<Compile Include="ImageUploaders\FlickrUploader.cs" />
|
||||||
<Compile Include="FileUploaders\FTPUploader.cs" />
|
|
||||||
<Compile Include="ImageUploaders\ImageBin.cs" />
|
<Compile Include="ImageUploaders\ImageBin.cs" />
|
||||||
<Compile Include="ImageUploaders\ImageShackUploader.cs" />
|
<Compile Include="ImageUploaders\ImageShackUploader.cs" />
|
||||||
<Compile Include="ImageUploaders\Img1Uploader.cs" />
|
<Compile Include="ImageUploaders\Img1Uploader.cs" />
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
<package id="MegaApiClient" version="1.0.4" targetFramework="net40" />
|
<package id="MegaApiClient" version="1.0.4" targetFramework="net40" />
|
||||||
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
|
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
|
||||||
<package id="SSH.NET" version="2014.4.6-beta1" targetFramework="net40" />
|
<package id="SSH.NET" version="2014.4.6-beta1" targetFramework="net40" />
|
||||||
|
<package id="System.Net.FtpClient" version="1.0.5200.21177" targetFramework="net40" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in a new issue