mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 15:50:57 +03:00
Allow specifying alternate path separator (for Windows SFTP implementations)
This commit is contained in:
@@ -19,11 +19,16 @@ import java.io.IOException;
|
||||
|
||||
public class PathHelper {
|
||||
|
||||
public static final String DEFAULT_SEPARATOR = "/";
|
||||
|
||||
private final SFTPEngine engine;
|
||||
private final String separator;
|
||||
|
||||
private String dotDir;
|
||||
|
||||
public PathHelper(SFTPEngine engine) {
|
||||
public PathHelper(SFTPEngine engine, String separator) {
|
||||
this.engine = engine;
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
public PathComponents getComponents(String path)
|
||||
@@ -31,7 +36,7 @@ public class PathHelper {
|
||||
if (path.isEmpty() || path.equals("."))
|
||||
return getComponents(getDotDir());
|
||||
|
||||
final int lastSlash = path.lastIndexOf("/");
|
||||
final int lastSlash = path.lastIndexOf(separator);
|
||||
|
||||
if (lastSlash == -1)
|
||||
if (path.equals(".."))
|
||||
|
||||
@@ -40,9 +40,13 @@ public class SFTPClient
|
||||
private final PathHelper pathHelper;
|
||||
|
||||
public SFTPClient(SFTPEngine engine) {
|
||||
this(engine, PathHelper.DEFAULT_SEPARATOR);
|
||||
}
|
||||
|
||||
public SFTPClient(SFTPEngine engine, String separator) {
|
||||
this.engine = engine;
|
||||
this.pathHelper = new PathHelper(engine);
|
||||
this.xfer = new SFTPFileTransfer(engine);
|
||||
this.pathHelper = new PathHelper(engine, separator);
|
||||
this.xfer = new SFTPFileTransfer(engine, pathHelper);
|
||||
}
|
||||
|
||||
public SFTPEngine getSFTPEngine() {
|
||||
|
||||
@@ -40,9 +40,15 @@ public class SFTPFileTransfer
|
||||
private volatile LocalFileFilter uploadFilter;
|
||||
private volatile RemoteResourceFilter downloadFilter;
|
||||
|
||||
public SFTPFileTransfer(SFTPEngine engine, PathHelper pathHelper) {
|
||||
this.engine = engine;
|
||||
this.pathHelper = pathHelper;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SFTPFileTransfer(SFTPEngine engine) {
|
||||
this.engine = engine;
|
||||
this.pathHelper = new PathHelper(engine);
|
||||
this.pathHelper = new PathHelper(engine, PathHelper.DEFAULT_SEPARATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user