diff --git a/src/main/java/com/xebialabs/overthere/ssh/SshConnectionBuilder.java b/src/main/java/com/xebialabs/overthere/ssh/SshConnectionBuilder.java index 90bf1d54..ce95ce39 100644 --- a/src/main/java/com/xebialabs/overthere/ssh/SshConnectionBuilder.java +++ b/src/main/java/com/xebialabs/overthere/ssh/SshConnectionBuilder.java @@ -508,6 +508,9 @@ public SshConnectionBuilder(String type, ConnectionOptions options, AddressPortM case SFTP_WINSSHD: connection = new SshSftpWinSshdConnection(type, options, mapper); break; + case SFTP_FREESSHD: + connection = new SshSftpFreeSshdConnection(type, options, mapper); + break; case SCP: connection = new SshScpConnection(type, options, mapper); break; diff --git a/src/main/java/com/xebialabs/overthere/ssh/SshConnectionType.java b/src/main/java/com/xebialabs/overthere/ssh/SshConnectionType.java index 83069c2f..5bfc90e9 100644 --- a/src/main/java/com/xebialabs/overthere/ssh/SshConnectionType.java +++ b/src/main/java/com/xebialabs/overthere/ssh/SshConnectionType.java @@ -42,6 +42,11 @@ public enum SshConnectionType { */ SFTP_WINSSHD, + /** + * An SSH connection that uses SFTP to transfer files, to a Windows host running freeSSHd. + */ + SFTP_FREESSHD, + /** * An SSH connection that uses SCP to transfer files, to a Unix host. */ diff --git a/src/main/java/com/xebialabs/overthere/ssh/SshSftpFreeSshdConnection.java b/src/main/java/com/xebialabs/overthere/ssh/SshSftpFreeSshdConnection.java new file mode 100644 index 00000000..2a3b1124 --- /dev/null +++ b/src/main/java/com/xebialabs/overthere/ssh/SshSftpFreeSshdConnection.java @@ -0,0 +1,44 @@ +package com.xebialabs.overthere.ssh; + +import com.xebialabs.overthere.ConnectionOptions; +import com.xebialabs.overthere.RuntimeIOException; +import com.xebialabs.overthere.spi.AddressPortMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static com.xebialabs.overthere.OperatingSystemFamily.WINDOWS; +import static com.xebialabs.overthere.ssh.SshConnectionBuilder.SSH_PROTOCOL; +import static com.xebialabs.overthere.util.OverthereUtils.checkArgument; +import static java.lang.String.format; + +public class SshSftpFreeSshdConnection extends SshSftpConnection { + private static Logger logger = LoggerFactory.getLogger(SshSftpWinSshdConnection.class); + + public SshSftpFreeSshdConnection(String type, ConnectionOptions options, AddressPortMapper mapper) { + super(type, options, mapper); + checkArgument(os == WINDOWS, "Cannot create a " + SSH_PROTOCOL + ":%s connection to a host that is not running Windows", sshConnectionType.toString() + .toLowerCase()); + } + + @Override + protected String pathToSftpPath(String path) { + String translatedPath; + boolean escaped = path.startsWith("\""); + String rawPath = path; + if (escaped) { + rawPath = path.substring(1); + } + + if (rawPath.length() >= 2 && rawPath.charAt(1) == ':') { + String pathInDrive = rawPath.substring(2).replace('\\', '/'); + translatedPath = "/" + pathInDrive; + if (escaped) { + translatedPath = "\"" + translatedPath; + } + } else { + throw new RuntimeIOException(format("Cannot translate Windows path [%s] to a FreeSshd path because it is not a Windows path", path)); + } + logger.trace("Translated Windows path [{}] to FreeSshd path [{}]", path, translatedPath); + return translatedPath; + } +} \ No newline at end of file