Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 367dc84

Browse files
authored
GeneXusFtps client remove function implementation (#95)
1 parent 84e9078 commit 367dc84

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

GeneXusFtps/src/main/java/com/genexus/commons/ftps/FtpsClientObject.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public FtpsClientObject()
1313
public abstract boolean connect(FtpsOptions options);
1414
public abstract boolean put(String localPath, String remoteDir);
1515
public abstract boolean get(String remoteFilePath, String localDir);
16+
public abstract boolean rm(String remoteFilePath);
1617
public abstract void disconnect();
1718
public abstract String getWorkingDirectory();
1819
}

GeneXusFtps/src/main/java/com/genexus/ftps/FtpsClient.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,38 @@ public boolean get(String remoteFilePath, String localDir) {
188188
return true;
189189

190190
}
191+
192+
public boolean rm(String remoteFilePath) {
193+
if (this.client == null || !this.client.isConnected()) {
194+
this.error.setError("FS019", "The connection is invalid, reconect");
195+
return false;
196+
}
197+
boolean dirchange = true;
198+
try {
199+
if (!isSameDir(getDirectory(remoteFilePath), this.client.printWorkingDirectory())) {
200+
dirchange = this.client.changeWorkingDirectory(getDirectory(remoteFilePath));
201+
this.pwd = getDirectory(remoteFilePath);
202+
}
203+
204+
} catch (IOException e2) {
205+
this.error.setError("FS020", "Error changing directory " + e2.getMessage());
206+
return false;
207+
}
208+
if (!dirchange) {
209+
this.error.setError("FS021",
210+
"Reply code: " + this.client.getReplyCode() + " Reply String: " + this.client.getReplyString());
211+
return false;
212+
}
213+
boolean deleted = false;
214+
try {
215+
deleted = this.client.deleteFile(remoteFilePath);
216+
} catch (Exception e) {
217+
this.error.setError("FS022", "Error retrieving file " + e.getMessage());
218+
deleted = false;
219+
}
220+
return deleted;
221+
222+
}
191223

192224
public void disconnect() {
193225
if (this.client != null && this.client.isConnected()) {

0 commit comments

Comments
 (0)