Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "ftp"
version = "2.14.1"
version = "2.15.0"
authors = ["Ballerina"]
keywords = ["FTP", "SFTP", "remote file", "file transfer", "client", "service"]
repository = "https://github.com/ballerina-platform/module-ballerina-ftp"
Expand Down Expand Up @@ -45,5 +45,5 @@ path = "./lib/commons-lang3-3.18.0.jar"
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "ftp-native"
version = "2.14.1"
path = "../native/build/libs/ftp-native-2.14.1.jar"
version = "2.15.0"
path = "../native/build/libs/ftp-native-2.15.0-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "ftp-compiler-plugin"
class = "io.ballerina.stdlib.ftp.plugin.FtpCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.14.1.jar"
path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.15.0-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.12.0"
[[package]]
org = "ballerina"
name = "ftp"
version = "2.14.1"
version = "2.15.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down
2 changes: 1 addition & 1 deletion ballerina/commons.bal
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public type PrivateKey record {|
# + password - Password of the user
public type Credentials record {|
string username;
string password;
string password?;
|};

# Configurations for facilitating secure communication with a remote
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.caching=true
group=io.ballerina.stdlib
version=2.14.2-SNAPSHOT
version=2.15.0-SNAPSHOT

checkstylePluginVersion=10.12.0
testngVersion=7.6.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private FtpClient() {
public static Object initClientEndpoint(BObject clientEndpoint, BMap<Object, Object> config) {
String protocol = (config.getStringValue(StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_PROTOCOL)))
.getValue();
Map<String, String> authMap = FtpUtil.getAuthMap(config);
Map<String, String> authMap = FtpUtil.getAuthMap(config, protocol);
clientEndpoint.addNativeData(FtpConstants.ENDPOINT_CONFIG_USERNAME,
authMap.get(FtpConstants.ENDPOINT_CONFIG_USERNAME));
clientEndpoint.addNativeData(FtpConstants.ENDPOINT_CONFIG_PASS_KEY,
Expand Down
33 changes: 23 additions & 10 deletions native/src/main/java/io/ballerina/stdlib/ftp/util/FtpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ private FtpUtil() {

public static String createUrl(BObject clientConnector, String filePath) throws BallerinaFtpException {
String username = (String) clientConnector.getNativeData(FtpConstants.ENDPOINT_CONFIG_USERNAME);
String password = (String) clientConnector.getNativeData(FtpConstants.ENDPOINT_CONFIG_PASS_KEY);
String password = null;
Object storedPW = clientConnector.getNativeData(FtpConstants.ENDPOINT_CONFIG_PASS_KEY);
if (storedPW != null) {
password = (String) storedPW;
}
String host = (String) clientConnector.getNativeData(FtpConstants.ENDPOINT_CONFIG_HOST);
int port = (Integer) clientConnector.getNativeData(FtpConstants.ENDPOINT_CONFIG_PORT);
String protocol = (String) clientConnector.getNativeData(FtpConstants.ENDPOINT_CONFIG_PROTOCOL);
Expand All @@ -92,8 +96,8 @@ public static String createUrl(BMap config) throws BallerinaFtpException {
int port = extractPortValue(config.getIntValue(StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_PORT)));
final BMap auth = config.getMapValue(StringUtils.fromString(
FtpConstants.ENDPOINT_CONFIG_AUTH));
String username = null;
String password = null;
String username = FTP_ANONYMOUS_USERNAME;
String password = protocol.equals(FtpConstants.SCHEME_FTP) ? FTP_ANONYMOUS_PASSWORD : null;
if (auth != null) {
final BMap credentials = auth.getMapValue(StringUtils.fromString(
FtpConstants.ENDPOINT_CONFIG_CREDENTIALS));
Expand All @@ -103,16 +107,22 @@ public static String createUrl(BMap config) throws BallerinaFtpException {
if (username.isBlank()) {
throw new BallerinaFtpException("Username cannot be empty");
}
password = (credentials.getStringValue(StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_PASS_KEY)))
.getValue();
BString tempPassword = credentials.getStringValue(
StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_PASS_KEY));
if (tempPassword != null) {
password = tempPassword.getValue();
}
}
}
return createUrl(protocol, host, port, username, password, filePath);
}

private static String createUrl(String protocol, String host, int port, String username, String password,
String filePath) throws BallerinaFtpException {
String userInfo = username + ":" + password;
String userInfo = username;
if (password != null) {
userInfo = username + ":" + password;
}
final String normalizedPath = normalizeFtpPath(filePath);
try {
URI uri = new URI(protocol, userInfo, host, port, normalizedPath, null, null);
Expand All @@ -133,19 +143,22 @@ private static String normalizeFtpPath(String rawPath) {
return "/" + rawPath;
}

public static Map<String, String> getAuthMap(BMap config) {
public static Map<String, String> getAuthMap(BMap config, String protocol) {
final BMap auth = config.getMapValue(StringUtils.fromString(
FtpConstants.ENDPOINT_CONFIG_AUTH));
String username = FTP_ANONYMOUS_USERNAME;
String password = FTP_ANONYMOUS_PASSWORD;
String password = protocol.equals(FtpConstants.SCHEME_FTP) ? FTP_ANONYMOUS_PASSWORD : null;
if (auth != null) {
final BMap credentials = auth.getMapValue(StringUtils.fromString(
FtpConstants.ENDPOINT_CONFIG_CREDENTIALS));
if (credentials != null) {
username = (credentials.getStringValue(StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_USERNAME)))
.getValue();
password = (credentials.getStringValue(StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_PASS_KEY)))
.getValue();
BString tempPassword = credentials.getStringValue(
StringUtils.fromString(FtpConstants.ENDPOINT_CONFIG_PASS_KEY));
if (tempPassword != null) {
password = tempPassword.getValue();
}
}
}
Map<String, String> authMap = new HashMap<>();
Expand Down
Loading