Skip to content

Commit

Permalink
GeneXusFtps cliente remove function implementation (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrampone authored Dec 26, 2022
1 parent fe0d43d commit 02abda9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public abstract class IFtpsClientObject : SecurityAPIObject
#pragma warning disable CA1716 // Identifiers should not match keywords
public abstract bool Get(string remoteFilePath, string localDir);
#pragma warning restore CA1716 // Identifiers should not match keywords
public abstract bool Rm(string remoteFilePath);
public abstract void Disconnect();

public abstract string GetWorkingDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,45 @@ public override bool Get(string remoteFilePath, string localDir)
return true;
}

[SecuritySafeCritical]
[SecuritySafeCritical]
public override bool Rm(string remoteFilePath)
{
if (this.client == null || !this.client.IsConnected)
{
this.error.setError("FS019", "The connection is invalid, reconect");
return false;
}
try
{
if (!IsSameDir(Path.GetDirectoryName(remoteFilePath), this.client.GetWorkingDirectory()))
{
this.client.SetWorkingDirectory(Path.GetDirectoryName(remoteFilePath));

this.pwd = Path.GetDirectoryName(remoteFilePath);
}
}
catch (Exception e)
{
this.error.setError("FS020", "Error changing directory " + e.Message);
return false;
}

try
{

this.client.DeleteFile(remoteFilePath);
}
catch (Exception e1)
{
this.error.setError("FS021", "Error retrieving file " + e1.Message);
return false;
}


return true;
}

[SecuritySafeCritical]
public override void Disconnect()
{
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GeneXusFtps.GeneXusFtps;
using GeneXusFtps.GeneXusFtps;
using NUnit.Framework;
using SecurityAPICommons.Utils;
using SecurityAPITest.SecurityAPICommons.commons;
Expand Down Expand Up @@ -75,6 +75,19 @@ private void TestGet(FtpsClient client)
True(get, client);
}

private void TestRm(FtpsClient client)
{
bool rm = client.Rm(remoteFilePath);
True(rm, client);
}


private void TestGetFalse(FtpsClient client)
{
bool get = client.Get(remoteFilePath, localDir);
False(get, client);
}

[Test]
public void TestWithoutCert()
{
Expand All @@ -94,6 +107,26 @@ public void TestWithoutCert()
client.Disconnect();
}

[Test]
public void TestRemove()
{
FtpsOptions options = new FtpsOptions();
options.Host = host;
options.User = user;
options.Password = password;
options.Port = port;
options.ForceEncryption = forceEncryption;
options.ConnectionMode = connectionMode;
options.EncryptionMode = encryptionMode;
options.Protocol = protocol;
options.WhiteList = whiteList;
FtpsClient client = TestConnection(options);
TestPut(client);
TestRm(client);
TestGetFalse(client);
client.Disconnect();
}

[Test]
public void TestWithCert()
{
Expand Down

0 comments on commit 02abda9

Please sign in to comment.