You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2015/03/17 18:35:32 UTC
[2/4] mina-sshd git commit: [SSHD-429] Take into account local file
separator when sending/receiving files via SCP
[SSHD-429] Take into account local file separator when sending/receiving files via SCP
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/043c7df2
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/043c7df2
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/043c7df2
Branch: refs/heads/master
Commit: 043c7df206e95181137498b63d4cfab3d9cebe12
Parents: 6debaf5
Author: Guillaume Nodet <gn...@apache.org>
Authored: Tue Mar 17 12:07:46 2015 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Tue Mar 17 12:07:46 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/sshd/common/scp/ScpHelper.java | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/043c7df2/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
index d73be2a..c5f6ae6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
@@ -20,6 +20,7 @@ package org.apache.sshd.common.scp;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
+import java.io.File;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -161,7 +162,8 @@ public class ScpHelper {
}
Path file;
if (Files.exists(path) && Files.isDirectory(path)) {
- file = path.resolve(name);
+ String localName = name.replace('/', File.separatorChar);
+ file = path.resolve(localName);
} else if (!Files.exists(path) && Files.exists(path.getParent()) && Files.isDirectory(path.getParent())) {
file = path;
} else {
@@ -242,7 +244,8 @@ public class ScpHelper {
Path file;
if (Files.exists(path) && Files.isDirectory(path)) {
- file = path.resolve(name);
+ String localName = name.replace('/', File.separatorChar);
+ file = path.resolve(localName);
} else if (Files.exists(path) && Files.isRegularFile(path)) {
file = path;
} else if (!Files.exists(path) && Files.exists(path.getParent()) && Files.isDirectory(path.getParent())) {
@@ -310,7 +313,7 @@ public class ScpHelper {
}
String[] included = new DirectoryScanner(basedir, pattern).scan();
for (String path : included) {
- Path file = fileSystem.getPath(basedir + "/" + path);
+ Path file = resolveLocalPath(basedir + "/" + path);
if (Files.isRegularFile(file)) {
sendFile(file, preserve, bufferSize);
} else if (Files.isDirectory(file)) {
@@ -332,7 +335,7 @@ public class ScpHelper {
basedir = pattern.substring(0, lastSep);
pattern = pattern.substring(lastSep + 1);
}
- Path file = fileSystem.getPath(basedir + "/" + pattern);
+ Path file = resolveLocalPath(basedir + "/" + pattern);
if (!Files.exists(file)) {
throw new IOException(file + ": no such file or directory");
}
@@ -351,6 +354,11 @@ public class ScpHelper {
}
}
+ protected Path resolveLocalPath(String path) {
+ String localPath = (path == null) ? null : path.replace('/', File.separatorChar);
+ return fileSystem.getPath(localPath);
+ }
+
public void sendFile(Path path, boolean preserve, int bufferSize) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Sending file {}", path);