Skip to content
5 changes: 5 additions & 0 deletions ballerina/client_endpoint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ public enum Compression {
# + host - Target service URL
# + port - Port number of the remote service
# + auth - Authentication options
# + userDirIsRoot - If set to `true`, treats the login home directory as the root (`/`) and
# prevents the underlying VFS from attempting to change to the actual server root.
# If `false`, treats the actual server root as `/`, which may cause a `CWD /` command
# that can fail on servers restricting root access (e.g., chrooted environments).
public type ClientConfiguration record {|
Protocol protocol = FTP;
string host = "127.0.0.1";
int port = 21;
AuthConfiguration auth?;
boolean userDirIsRoot = false;
|};

isolated function getInputContent(string path, stream<byte[] & readonly, io:Error?>|string|xml|json content,
Expand Down
5 changes: 5 additions & 0 deletions ballerina/listener_endpoint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class Job {
# + path - Remote FTP directory location
# + fileNamePattern - File name pattern that event need to trigger
# + pollingInterval - Periodic time interval to check new update
# + userDirIsRoot - If set to `true`, treats the login home directory as the root (`/`) and
# prevents the underlying VFS from attempting to change to the actual server root.
# If `false`, treats the actual server root as `/`, which may cause a `CWD /` command
# that can fail on servers restricting root access (e.g., chrooted environments).
public type ListenerConfiguration record {|
Protocol protocol = FTP;
string host = "127.0.0.1";
Expand All @@ -167,6 +171,7 @@ public type ListenerConfiguration record {|
string path = "/";
string fileNamePattern?;
decimal pollingInterval = 60;
boolean userDirIsRoot = false;
|};

# Represents a FTP service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static Object initClientEndpoint(BObject clientEndpoint, BMap<Object, Obj
FtpUtil.extractPortValue(config.getIntValue(StringUtils.fromString(
FtpConstants.ENDPOINT_CONFIG_PORT))));
clientEndpoint.addNativeData(FtpConstants.ENDPOINT_CONFIG_PROTOCOL, protocol);
Map<String, String> ftpConfig = new HashMap<>(5);
Map<String, String> ftpConfig = new HashMap<>(6);
BMap auth = config.getMapValue(StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_AUTH));
if (auth != null) {
final BMap privateKey = auth.getMapValue(StringUtils.fromString(
Expand All @@ -96,7 +96,8 @@ public static Object initClientEndpoint(BObject clientEndpoint, BMap<Object, Obj
ftpConfig.put(ENDPOINT_CONFIG_PREFERRED_METHODS, FtpUtil.getPreferredMethodsFromAuthConfig(auth));
}
ftpConfig.put(FtpConstants.PASSIVE_MODE, String.valueOf(true));
ftpConfig.put(FtpConstants.USER_DIR_IS_ROOT, String.valueOf(false));
boolean userDirIsRoot = config.getBooleanValue(StringUtils.fromString("userDirIsRoot"));
ftpConfig.put(FtpConstants.USER_DIR_IS_ROOT, String.valueOf(userDirIsRoot));
ftpConfig.put(FtpConstants.AVOID_PERMISSION_CHECK, String.valueOf(true));
String url;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ private static void setSftpOptions(Map<String, String> options, FileSystemOption
final SftpFileSystemConfigBuilder configBuilder = SftpFileSystemConfigBuilder.getInstance();
String value = options.get(ENDPOINT_CONFIG_PREFERRED_METHODS);
configBuilder.setPreferredAuthentications(opts, value);
if (options.get(FtpConstants.USER_DIR_IS_ROOT) != null) {
configBuilder.setUserDirIsRoot(opts, false);
}
boolean userDirIsRoot = Boolean.parseBoolean(options.get(FtpConstants.USER_DIR_IS_ROOT));
configBuilder.setUserDirIsRoot(opts, userDirIsRoot);
if (options.get(FtpConstants.IDENTITY) != null) {
IdentityInfo identityInfo;
if (options.containsKey(IDENTITY_PASS_PHRASE)) {
Expand Down
Loading