diff --git a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs
index bb51d04c4..aa7a53a92 100644
--- a/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs
+++ b/dotnet/src/extensions/SecurityAPI/dotnet/dotnetframework/GeneXusSftp/Sftp/SftpClient.cs
@@ -51,27 +51,19 @@ public override bool Connect(SftpOptions options)
return false;
}
bool useKey = false;
- if (SecurityUtils.compareStrings("", options.KeyPath) || SecurityUtils.compareStrings("", options.User) || SecurityUtils.compareStrings("", options.KeyPassword))
- {
- useKey = false;
- if (SecurityUtils.compareStrings("", options.User)
- || SecurityUtils.compareStrings("", options.Password))
- {
-
- this.error.setError("SF001", "Authentication misconfiguration");
- return false;
- }
- else
- {
- useKey = false;
- }
- }
- else
- {
- useKey = true;
- }
-
-
+ if (!SecurityUtils.compareStrings("", options.KeyPath) )
+ {
+ useKey = true;
+ }else
+ {
+ if (SecurityUtils.compareStrings("", options.User)
+ || SecurityUtils.compareStrings("", options.Password))
+ {
+
+ this.error.setError("SF001", "Authentication misconfiguration. Missing user or password");
+ return false;
+ }
+ }
if (SecurityUtils.compareStrings("", options.Host))
{
@@ -318,9 +310,6 @@ private void SetupChannelSftp(SftpOptions options, bool useKey)
PrivateKeyFile keyFile = new PrivateKeyFile(options.KeyPath, options.KeyPassword);
method.Add(new PrivateKeyAuthenticationMethod(options.User, keyFile));
-
-
-
}
else
{
diff --git a/dotnet/src/extensions/SecurityAPI/test/dotnetcore/SecurityAPITestNetCore/SecurityAPITestNetCore.csproj b/dotnet/src/extensions/SecurityAPI/test/dotnetcore/SecurityAPITestNetCore/SecurityAPITestNetCore.csproj
index 12937f909..bfb50beb9 100644
--- a/dotnet/src/extensions/SecurityAPI/test/dotnetcore/SecurityAPITestNetCore/SecurityAPITestNetCore.csproj
+++ b/dotnet/src/extensions/SecurityAPI/test/dotnetcore/SecurityAPITestNetCore/SecurityAPITestNetCore.csproj
@@ -49,6 +49,7 @@
+
diff --git a/dotnet/src/extensions/SecurityAPI/test/dotnetframework/SecurityAPITest/Sftp/TestLoginWithKeyWithoutPassword.cs b/dotnet/src/extensions/SecurityAPI/test/dotnetframework/SecurityAPITest/Sftp/TestLoginWithKeyWithoutPassword.cs
new file mode 100644
index 000000000..5d46335c3
--- /dev/null
+++ b/dotnet/src/extensions/SecurityAPI/test/dotnetframework/SecurityAPITest/Sftp/TestLoginWithKeyWithoutPassword.cs
@@ -0,0 +1,74 @@
+using SecurityAPITest.SecurityAPICommons.commons;
+using NUnit.Framework;
+using Sftp.GeneXusSftp;
+using System.IO;
+using System;
+
+namespace SecurityAPITest.Sftp
+{
+ [TestFixture]
+ [RunIfRunSettingsConfigured]
+ public class TestLoginWithKeyWithoutPassword : SecurityAPITestObject
+ {
+ protected static string host;
+ protected static string user;
+ protected static string keyPath;
+ protected static string keyPassword;
+ protected static string localPath;
+ protected static string remoteDir;
+ protected static string remoteFilePath;
+ protected static string localDir;
+
+
+ [SetUp]
+ public virtual void SetUp()
+ {
+
+ host = TestContextParameter("gx_ftp_host");
+ user = TestContextParameter("gx_sftp_user");
+ string known_hosts_content_base64 = TestContextParameter("gx_ftp_known_hosts_content_base64");
+ keyPath = Path.Combine(BASE_PATH, "Temp", "sftptest", "key", "id_rsa");
+ string id_rsaConentBase64 = TestContextParameter("gx_ftp_id_rsa_content_base64");
+ File.WriteAllBytes(keyPath, Convert.FromBase64String(id_rsaConentBase64));
+ keyPassword = TestContextParameter("gx_sftp_key_password");
+ localPath = Path.Combine(BASE_PATH, "Temp", "sftptest", "sftptest1.txt");
+ remoteDir = "sftp";
+ remoteFilePath = "sftp/sftptest1.txt";
+ localDir = Path.Combine(BASE_PATH, "Temp", "sftptest", "back");
+ }
+
+ private SftpClient TestConnection(SftpOptions options)
+ {
+ SftpClient client = new SftpClient();
+ bool connected = client.Connect(options);
+ True(connected, client);
+ return client;
+ }
+
+ private void TestPut(SftpClient client)
+ {
+ bool put = client.Put(localPath, remoteDir);
+ True(put, client);
+ }
+
+ private void TestGet(SftpClient client)
+ {
+ bool get = client.Get(remoteFilePath, localDir);
+ True(get, client);
+ }
+
+ [Test]
+ public void TestWithKey()
+ {
+ SftpOptions options = new SftpOptions();
+ options.Host = host;
+ options.User = user;
+ options.AllowHostKeyChecking = false;
+ options.KeyPassword = keyPassword;
+ SftpClient client = TestConnection(options);
+ TestPut(client);
+ TestGet(client);
+ client.Disconnect();
+ }
+ }
+}