FTP Client button check for SFTP

This commit is contained in:
Jaex 2014-06-25 00:41:55 +03:00
parent 99e9bbc7c8
commit 75b09c29a6
3 changed files with 44 additions and 33 deletions

View file

@ -103,17 +103,20 @@ public FTP(FTPAccount account)
}
}
#region FileUploader methods
public override UploadResult Upload(Stream stream, string fileName)
{
UploadResult result = new UploadResult();
fileName = Helpers.GetValidURL(fileName);
string path = Account.GetSubFolderPath(fileName);
bool uploadResult;
try
{
IsUploading = true;
UploadData(stream, path);
uploadResult = UploadData(stream, path);
}
finally
{
@ -121,7 +124,7 @@ public override UploadResult Upload(Stream stream, string fileName)
IsUploading = false;
}
if (!StopUploadRequested && !IsError)
if (uploadResult && !StopUploadRequested && !IsError)
{
result.URL = Account.GetUriPath(fileName);
}
@ -138,6 +141,8 @@ public override void StopUpload()
}
}
#endregion FileUploader methods
public bool Connect()
{
if (!client.IsConnected)

View file

@ -61,31 +61,30 @@ public SFTP(FTPAccount account)
Account = account;
}
#region FileUploader methods
public override UploadResult Upload(Stream stream, string fileName)
{
UploadResult result = new UploadResult();
if (Connect())
fileName = Helpers.GetValidURL(fileName);
string path = Account.GetSubFolderPath(fileName);
bool uploadResult;
try
{
fileName = Helpers.GetValidURL(fileName);
string folderPath = Account.GetSubFolderPath();
string filePath = URLHelpers.CombineURL(folderPath, fileName);
IsUploading = true;
uploadResult = UploadStream(stream, path);
}
finally
{
Dispose();
IsUploading = false;
}
try
{
IsUploading = true;
UploadStream(stream, filePath);
}
finally
{
Dispose();
IsUploading = false;
}
if (!StopUploadRequested && !IsError)
{
result.URL = Account.GetUriPath(fileName);
}
if (uploadResult && !StopUploadRequested && !IsError)
{
result.URL = Account.GetUriPath(fileName);
}
return result;
@ -100,6 +99,8 @@ public override void StopUpload()
}
}
#endregion FileUploader methods
public bool Connect()
{
if (client == null)
@ -209,24 +210,29 @@ public List<string> CreateMultiDirectory(string path)
return directoryList;
}
private void UploadStream(Stream stream, string remotePath)
private bool UploadStream(Stream stream, string remotePath)
{
try
if (Connect())
{
using (SftpFileStream sftpStream = client.OpenWrite(remotePath))
try
{
TransferData(stream, sftpStream);
using (SftpFileStream sftpStream = client.OpenWrite(remotePath))
{
return TransferData(stream, sftpStream);
}
}
}
catch (SftpPathNotFoundException)
{
CreateDirectory(URLHelpers.GetDirectoryPath(remotePath));
catch (SftpPathNotFoundException)
{
CreateDirectory(URLHelpers.GetDirectoryPath(remotePath));
using (SftpFileStream sftpStream = client.OpenWrite(remotePath))
{
TransferData(stream, sftpStream);
using (SftpFileStream sftpStream = client.OpenWrite(remotePath))
{
return TransferData(stream, sftpStream);
}
}
}
return false;
}
public void Dispose()

View file

@ -1002,7 +1002,7 @@ private void FTPOpenClient()
{
FTPAccount account = GetSelectedFTPAccount();
if (account != null)
if (account != null && (account.Protocol == FTPProtocol.FTP || account.Protocol == FTPProtocol.FTPS))
{
new FTPClientForm(account).Show();
}