You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2016/02/18 15:38:41 UTC
mina-sshd git commit: Re-organized SftpClient creation methods same
as ScpClient ones
Repository: mina-sshd
Updated Branches:
refs/heads/master 4a8c81717 -> fd2a22f58
Re-organized SftpClient creation methods same as ScpClient ones
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/fd2a22f5
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/fd2a22f5
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/fd2a22f5
Branch: refs/heads/master
Commit: fd2a22f58623547f10733cd38418f5d4a794e336
Parents: 4a8c817
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Thu Feb 18 16:39:23 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Thu Feb 18 16:39:23 2016 +0200
----------------------------------------------------------------------
.../sshd/client/session/ClientSession.java | 49 +------
.../sshd/client/subsystem/sftp/SftpClient.java | 128 ++++++++++++++++++-
.../subsystem/sftp/SftpClientCreator.java | 71 ++++++++++
.../common/subsystem/sftp/SftpConstants.java | 8 ++
4 files changed, 208 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fd2a22f5/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
index d9633b0..6432ffe 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientSession.java
@@ -20,7 +20,6 @@ package org.apache.sshd.client.session;
import java.io.IOException;
import java.net.SocketAddress;
-import java.nio.file.FileSystem;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@@ -34,8 +33,7 @@ import org.apache.sshd.client.channel.ChannelSubsystem;
import org.apache.sshd.client.channel.ClientChannel;
import org.apache.sshd.client.future.AuthFuture;
import org.apache.sshd.client.scp.ScpClientCreator;
-import org.apache.sshd.client.subsystem.sftp.SftpClient;
-import org.apache.sshd.client.subsystem.sftp.SftpVersionSelector;
+import org.apache.sshd.client.subsystem.sftp.SftpClientCreator;
import org.apache.sshd.common.future.KeyExchangeFuture;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.net.SshdSocketAddress;
@@ -69,7 +67,7 @@ import org.apache.sshd.common.util.net.SshdSocketAddress;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public interface ClientSession
- extends Session, ScpClientCreator,
+ extends Session, ScpClientCreator, SftpClientCreator,
ClientAuthenticationManager {
enum ClientSessionEvent {
TIMEOUT,
@@ -159,49 +157,6 @@ public interface ClientSession
ChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException;
/**
- * Create an SFTP client from this session.
- *
- * @return The created {@link SftpClient}
- * @throws IOException if failed to create the client
- */
- SftpClient createSftpClient() throws IOException;
-
- /**
- * Creates an SFTP client using the specified version
- *
- * @param version The version to use - <B>Note:</B> if the specified
- * version is not supported by the server then an exception
- * will occur
- * @return The created {@link SftpClient}
- * @throws IOException If failed to create the client or use the specified version
- */
- SftpClient createSftpClient(int version) throws IOException;
-
- /**
- * Creates an SFTP client while allowing the selection of a specific version
- *
- * @param selector The {@link SftpVersionSelector} to use - <B>Note:</B>
- * if the server does not support versions re-negotiation then the
- * selector will be presented with only one "choice" - the
- * current version
- * @return The created {@link SftpClient}
- * @throws IOException If failed to create the client or re-negotiate
- */
- SftpClient createSftpClient(SftpVersionSelector selector) throws IOException;
-
- FileSystem createSftpFileSystem() throws IOException;
-
- FileSystem createSftpFileSystem(int version) throws IOException;
-
- FileSystem createSftpFileSystem(SftpVersionSelector selector) throws IOException;
-
- FileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException;
-
- FileSystem createSftpFileSystem(int version, int readBufferSize, int writeBufferSize) throws IOException;
-
- FileSystem createSftpFileSystem(SftpVersionSelector selector, int readBufferSize, int writeBufferSize) throws IOException;
-
- /**
* Start forwarding the given local address on the client to the given address on the server.
*
* @param local The local address
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fd2a22f5/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
index 7c911f7..3669882 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClient.java
@@ -432,6 +432,9 @@ public interface SftpClient extends SubsystemClient {
String SFTP_CHANNEL_OPEN_TIMEOUT = "sftp-channel-open-timeout";
long DEFAULT_CHANNEL_OPEN_TIMEOUT = DEFAULT_WAIT_TIMEOUT;
+ /**
+ * @return The negotiated SFTP protocol version
+ */
int getVersion();
/**
@@ -476,8 +479,18 @@ public interface SftpClient extends SubsystemClient {
*/
CloseableHandle open(String path, Collection<OpenMode> options) throws IOException;
+ /**
+ * Close the handle obtained from one of the {@code open} methods
+ *
+ * @param handle The {@code Handle} to close
+ * @throws IOException If failed to execute
+ */
void close(Handle handle) throws IOException;
+ /**
+ * @param path The remote path to remove
+ * @throws IOException If failed to execute
+ */
void remove(String path) throws IOException;
void rename(String oldPath, String newPath) throws IOException;
@@ -535,12 +548,41 @@ public interface SftpClient extends SubsystemClient {
void write(Handle handle, long fileOffset, byte[] src) throws IOException;
+ /**
+ * Write data to (open) file handle
+ *
+ * @param handle The file {@link Handle}
+ * @param fileOffset Zero-based offset to write in file
+ * @param src Data buffer
+ * @param srcOffset Offset of valid data in buffer
+ * @param len Number of bytes to write
+ * @throws IOException If failed to write the data
+ */
void write(Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws IOException;
+ /**
+ * Create remote directory
+ *
+ * @param path Remote directory path
+ * @throws IOException If failed to execute
+ */
void mkdir(String path) throws IOException;
+ /**
+ * Remove remote directory
+ *
+ * @param path Remote directory path
+ * @throws IOException If failed to execute
+ */
void rmdir(String path) throws IOException;
+ /**
+ * Obtain a handle for a directory
+ *
+ * @param path Remote directory path
+ * @return The associated directory {@link Handle}
+ * @throws IOException If failed to execute
+ */
CloseableHandle openDir(String path) throws IOException;
/**
@@ -568,26 +610,92 @@ public interface SftpClient extends SubsystemClient {
*/
List<DirEntry> readDir(Handle handle, AtomicReference<Boolean> eolIndicator) throws IOException;
+ /**
+ * The effective "normalized" remote path
+ *
+ * @param path The requested path - may be relative, and/or contain
+ * dots - e.g., ".", "..", "./foo", "../bar"
+ *
+ * @return The effective "normalized" remote path
+ * @throws IOException If failed to execute
+ */
String canonicalPath(String path) throws IOException;
+ /**
+ * Retrieve remote path meta-data - follow symbolic links if encountered
+ *
+ * @param path The remote path
+ * @return The associated {@link Attributes}
+ * @throws IOException If failed to execute
+ */
Attributes stat(String path) throws IOException;
+ /**
+ * Retrieve remote path meta-data - do <B>not</B> follow symbolic links
+ *
+ * @param path The remote path
+ * @return The associated {@link Attributes}
+ * @throws IOException If failed to execute
+ */
Attributes lstat(String path) throws IOException;
+ /**
+ * Retrieve file/directory handle meta-data
+ *
+ * @param handle The {@link Handle} obtained via one of the {@code open} calls
+ * @return The associated {@link Attributes}
+ * @throws IOException If failed to execute
+ */
Attributes stat(Handle handle) throws IOException;
+ /**
+ * Update remote node meta-data
+ *
+ * @param path The remote path
+ * @param attributes The {@link Attributes} to update
+ * @throws IOException If failed to execute
+ */
void setStat(String path, Attributes attributes) throws IOException;
+ /**
+ * Update remote node meta-data
+ *
+ * @param handle The {@link Handle} obtained via one of the {@code open} calls
+ * @param attributes The {@link Attributes} to update
+ * @throws IOException If failed to execute
+ */
void setStat(Handle handle, Attributes attributes) throws IOException;
+ /**
+ * Retrieve target of a link
+ *
+ * @param path Remote path that represents a link
+ * @return The link target
+ * @throws IOException If failed to execute
+ */
String readLink(String path) throws IOException;
+ /**
+ * Create symbolic link
+ *
+ * @param linkPath The link location
+ * @param targetPath The referenced target by the link
+ * @throws IOException If failed to execute
+ */
void symLink(String linkPath, String targetPath) throws IOException;
+ /**
+ * Create a link
+ *
+ * @param linkPath The link location
+ * @param targetPath The referenced target by the link
+ * @param symbolic If {@code true} then make this a symbolic link, otherwise a hard one
+ * @throws IOException If failed to execute
+ */
void link(String linkPath, String targetPath, boolean symbolic) throws IOException;
+ // see SSH_FXP_BLOCK / SSH_FXP_UNBLOCK for byte range locks
void lock(Handle handle, long offset, long length, int mask) throws IOException;
-
void unlock(Handle handle, long offset, long length) throws IOException;
//
@@ -613,6 +721,15 @@ public interface SftpClient extends SubsystemClient {
InputStream read(String path, Collection<OpenMode> mode) throws IOException;
+ /**
+ * Read a remote file's data via an input stream
+ *
+ * @param path The remote file path
+ * @param bufferSize The internal read buffer size
+ * @param mode The remote file {@link OpenMode}s
+ * @return An {@link InputStream} for reading the remote file data
+ * @throws IOException If failed to execute
+ */
InputStream read(String path, int bufferSize, Collection<OpenMode> mode) throws IOException;
OutputStream write(String path) throws IOException;
@@ -625,6 +742,15 @@ public interface SftpClient extends SubsystemClient {
OutputStream write(String path, Collection<OpenMode> mode) throws IOException;
+ /**
+ * Write to a remote file via an output stream
+ *
+ * @param path The remote file path
+ * @param bufferSize The internal write buffer size
+ * @param mode The remote file {@link OpenMode}s
+ * @return An {@link OutputStream} for writing the data
+ * @throws IOException If failed to execute
+ */
OutputStream write(String path, int bufferSize, Collection<OpenMode> mode) throws IOException;
/**
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fd2a22f5/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java
new file mode 100644
index 0000000..09b0843
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/client/subsystem/sftp/SftpClientCreator.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.client.subsystem.sftp;
+
+import java.io.IOException;
+import java.nio.file.FileSystem;
+
+/**
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public interface SftpClientCreator {
+ /**
+ * Create an SFTP client from this session.
+ *
+ * @return The created {@link SftpClient}
+ * @throws IOException if failed to create the client
+ */
+ SftpClient createSftpClient() throws IOException;
+
+ /**
+ * Creates an SFTP client using the specified version
+ *
+ * @param version The version to use - <B>Note:</B> if the specified
+ * version is not supported by the server then an exception
+ * will occur
+ * @return The created {@link SftpClient}
+ * @throws IOException If failed to create the client or use the specified version
+ */
+ SftpClient createSftpClient(int version) throws IOException;
+
+ /**
+ * Creates an SFTP client while allowing the selection of a specific version
+ *
+ * @param selector The {@link SftpVersionSelector} to use - <B>Note:</B>
+ * if the server does not support versions re-negotiation then the
+ * selector will be presented with only one "choice" - the
+ * current version
+ * @return The created {@link SftpClient}
+ * @throws IOException If failed to create the client or re-negotiate
+ */
+ SftpClient createSftpClient(SftpVersionSelector selector) throws IOException;
+
+ FileSystem createSftpFileSystem() throws IOException;
+
+ FileSystem createSftpFileSystem(int version) throws IOException;
+
+ FileSystem createSftpFileSystem(SftpVersionSelector selector) throws IOException;
+
+ FileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException;
+
+ FileSystem createSftpFileSystem(int version, int readBufferSize, int writeBufferSize) throws IOException;
+
+ FileSystem createSftpFileSystem(SftpVersionSelector selector, int readBufferSize, int writeBufferSize) throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fd2a22f5/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
index 296c8ed..47042ef 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/subsystem/sftp/SftpConstants.java
@@ -20,6 +20,7 @@ package org.apache.sshd.common.subsystem.sftp;
import java.lang.reflect.Field;
import java.util.Map;
+
import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.Predicate;
import org.apache.sshd.common.util.logging.LoggingUtils;
@@ -157,6 +158,13 @@ public final class SftpConstants {
public static final int SSH_FXF_READ_LOCK = 0x00000040;
public static final int SSH_FXF_WRITE_LOCK = 0x00000080;
public static final int SSH_FXF_DELETE_LOCK = 0x00000100;
+ public static final int SSH_FXF_BLOCK_ADVISORY = 0x00000200;
+ public static final int SSH_FXF_NOFOLLOW = 0x00000400;
+ public static final int SSH_FXF_DELETE_ON_CLOSE = 0x00000800;
+ public static final int SSH_FXF_ACCESS_AUDIT_ALARM_INFO = 0x00001000;
+ public static final int SSH_FXF_ACCESS_BACKUP = 0x00002000;
+ public static final int SSH_FXF_BACKUP_STREAM = 0x00004000;
+ public static final int SSH_FXF_OVERRIDE_OWNER = 0x00008000;
public static final int SSH_FXP_RENAME_OVERWRITE = 0x00000001;
public static final int SSH_FXP_RENAME_ATOMIC = 0x00000002;