aboutsummaryrefslogtreecommitdiffstats
path: root/sshlib/src/main/java/com/trilead/ssh2/sftp
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-07-18 11:30:18 -0700
committerKenny Root <kenny@the-b.org>2015-07-18 11:30:18 -0700
commit2f5f3754dce85212a71138fd80c2300b73461908 (patch)
treeac51a1c9f143bc77a0cfec2e7da1b7c184394a98 /sshlib/src/main/java/com/trilead/ssh2/sftp
parent0cf7ac30faecc82e04b080f418b08758624b07f5 (diff)
downloadsshlib-2f5f3754dce85212a71138fd80c2300b73461908.tar.gz
sshlib-2f5f3754dce85212a71138fd80c2300b73461908.tar.bz2
sshlib-2f5f3754dce85212a71138fd80c2300b73461908.zip
Rename project to sshlib
Diffstat (limited to 'sshlib/src/main/java/com/trilead/ssh2/sftp')
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/AttrTextHints.java38
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/AttribBits.java129
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/AttribFlags.java112
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/AttribPermissions.java32
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/AttribTypes.java28
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/ErrorCodes.java104
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/OpenFlags.java223
-rw-r--r--sshlib/src/main/java/com/trilead/ssh2/sftp/Packet.java43
8 files changed, 709 insertions, 0 deletions
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/AttrTextHints.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttrTextHints.java
new file mode 100644
index 0000000..19f0525
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttrTextHints.java
@@ -0,0 +1,38 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * Values for the 'text-hint' field in the SFTP ATTRS data type.
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: AttrTextHints.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ *
+ */
+public class AttrTextHints
+{
+ /**
+ * The server knows the file is a text file, and should be opened
+ * using the SSH_FXF_ACCESS_TEXT_MODE flag.
+ */
+ public static final int SSH_FILEXFER_ATTR_KNOWN_TEXT = 0x00;
+
+ /**
+ * The server has applied a heuristic or other mechanism and
+ * believes that the file should be opened with the
+ * SSH_FXF_ACCESS_TEXT_MODE flag.
+ */
+ public static final int SSH_FILEXFER_ATTR_GUESSED_TEXT = 0x01;
+
+ /**
+ * The server knows the file has binary content.
+ */
+ public static final int SSH_FILEXFER_ATTR_KNOWN_BINARY = 0x02;
+
+ /**
+ * The server has applied a heuristic or other mechanism and
+ * believes has binary content, and should not be opened with the
+ * SSH_FXF_ACCESS_TEXT_MODE flag.
+ */
+ public static final int SSH_FILEXFER_ATTR_GUESSED_BINARY = 0x03;
+}
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribBits.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribBits.java
new file mode 100644
index 0000000..b143613
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribBits.java
@@ -0,0 +1,129 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * SFTP Attribute Bits for the "attrib-bits" and "attrib-bits-valid" fields
+ * of the SFTP ATTR data type.
+ * <p>
+ * Yes, these are the "attrib-bits", even though they have "_FLAGS_" in
+ * their name. Don't ask - I did not invent it.
+ * <p>
+ * "<i>These fields, taken together, reflect various attributes of the file
+ * or directory, on the server. Bits not set in 'attrib-bits-valid' MUST be
+ * ignored in the 'attrib-bits' field. This allows both the server and the
+ * client to communicate only the bits it knows about without inadvertently
+ * twiddling bits they don't understand.</i>"
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: AttribBits.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ *
+ */
+public class AttribBits
+{
+ /**
+ * Advisory, read-only bit. This bit is not part of the access
+ * control information on the file, but is rather an advisory field
+ * indicating that the file should not be written.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_READONLY = 0x00000001;
+
+ /**
+ * The file is part of the operating system.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_SYSTEM = 0x00000002;
+
+ /**
+ * File SHOULD NOT be shown to user unless specifically requested.
+ * For example, most UNIX systems SHOULD set this bit if the filename
+ * begins with a 'period'. This bit may be read-only (see section 5.4 of
+ * the SFTP standard draft). Most UNIX systems will not allow this to be
+ * changed.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_HIDDEN = 0x00000004;
+
+ /**
+ * This attribute applies only to directories. This attribute is
+ * always read-only, and cannot be modified. This attribute means
+ * that files and directory names in this directory should be compared
+ * without regard to case.
+ * <p>
+ * It is recommended that where possible, the server's filesystem be
+ * allowed to do comparisons. For example, if a client wished to prompt
+ * a user before overwriting a file, it should not compare the new name
+ * with the previously retrieved list of names in the directory. Rather,
+ * it should first try to create the new file by specifying
+ * SSH_FXF_CREATE_NEW flag. Then, if this fails and returns
+ * SSH_FX_FILE_ALREADY_EXISTS, it should prompt the user and then retry
+ * the create specifying SSH_FXF_CREATE_TRUNCATE.
+ * <p>
+ * Unless otherwise specified, filenames are assumed to be case sensitive.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE = 0x00000008;
+
+ /**
+ * The file should be included in backup / archive operations.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_ARCHIVE = 0x00000010;
+
+ /**
+ * The file is stored on disk using file-system level transparent
+ * encryption. This flag does not affect the file data on the wire
+ * (for either READ or WRITE requests.)
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED = 0x00000020;
+
+ /**
+ * The file is stored on disk using file-system level transparent
+ * compression. This flag does not affect the file data on the wire.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_COMPRESSED = 0x00000040;
+
+ /**
+ * The file is a sparse file; this means that file blocks that have
+ * not been explicitly written are not stored on disk. For example, if
+ * a client writes a buffer at 10 M from the beginning of the file,
+ * the blocks between the previous EOF marker and the 10 M offset would
+ * not consume physical disk space.
+ * <p>
+ * Some servers may store all files as sparse files, in which case
+ * this bit will be unconditionally set. Other servers may not have
+ * a mechanism for determining if the file is sparse, and so the file
+ * MAY be stored sparse even if this flag is not set.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_SPARSE = 0x00000080;
+
+ /**
+ * Opening the file without either the SSH_FXF_ACCESS_APPEND_DATA or
+ * the SSH_FXF_ACCESS_APPEND_DATA_ATOMIC flag (see section 8.1.1.3
+ * of the SFTP standard draft) MUST result in an
+ * SSH_FX_INVALID_PARAMETER error.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY = 0x00000100;
+
+ /**
+ * The file cannot be deleted or renamed, no hard link can be created
+ * to this file, and no data can be written to the file.
+ * <p>
+ * This bit implies a stronger level of protection than
+ * SSH_FILEXFER_ATTR_FLAGS_READONLY, the file permission mask or ACLs.
+ * Typically even the superuser cannot write to immutable files, and
+ * only the superuser can set or remove the bit.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE = 0x00000200;
+
+ /**
+ * When the file is modified, the changes are written synchronously
+ * to the disk.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_SYNC = 0x00000400;
+
+ /**
+ * The server MAY include this bit in a directory listing or realpath
+ * response. It indicates there was a failure in the translation to UTF-8.
+ * If this flag is included, the server SHOULD also include the
+ * UNTRANSLATED_NAME attribute.
+ */
+ public static final int SSH_FILEXFER_ATTR_FLAGS_TRANSLATION_ERR = 0x00000800;
+
+}
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribFlags.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribFlags.java
new file mode 100644
index 0000000..ea27871
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribFlags.java
@@ -0,0 +1,112 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * Attribute Flags. The 'valid-attribute-flags' field in
+ * the SFTP ATTRS data type specifies which of the fields are actually present.
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: AttribFlags.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ *
+ */
+public class AttribFlags
+{
+ /**
+ * Indicates that the 'allocation-size' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_SIZE = 0x00000001;
+
+ /** Protocol version 6:
+ * 0x00000002 was used in a previous version of this protocol.
+ * It is now a reserved value and MUST NOT appear in the mask.
+ * Some future version of this protocol may reuse this value.
+ */
+ public static final int SSH_FILEXFER_ATTR_V3_UIDGID = 0x00000002;
+
+ /**
+ * Indicates that the 'permissions' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004;
+
+ /**
+ * Indicates that the 'atime' and 'mtime' field are present
+ * (protocol v3).
+ */
+ public static final int SSH_FILEXFER_ATTR_V3_ACMODTIME = 0x00000008;
+
+ /**
+ * Indicates that the 'atime' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_ACCESSTIME = 0x00000008;
+
+ /**
+ * Indicates that the 'createtime' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_CREATETIME = 0x00000010;
+
+ /**
+ * Indicates that the 'mtime' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_MODIFYTIME = 0x00000020;
+
+ /**
+ * Indicates that the 'acl' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_ACL = 0x00000040;
+
+ /**
+ * Indicates that the 'owner' and 'group' fields are present.
+ */
+ public static final int SSH_FILEXFER_ATTR_OWNERGROUP = 0x00000080;
+
+ /**
+ * Indicates that additionally to the 'atime', 'createtime',
+ * 'mtime' and 'ctime' fields (if present), there is also
+ * 'atime-nseconds', 'createtime-nseconds', 'mtime-nseconds'
+ * and 'ctime-nseconds'.
+ */
+ public static final int SSH_FILEXFER_ATTR_SUBSECOND_TIMES = 0x00000100;
+
+ /**
+ * Indicates that the 'attrib-bits' and 'attrib-bits-valid'
+ * fields are present.
+ */
+ public static final int SSH_FILEXFER_ATTR_BITS = 0x00000200;
+
+ /**
+ * Indicates that the 'allocation-size' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_ALLOCATION_SIZE = 0x00000400;
+
+ /**
+ * Indicates that the 'text-hint' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_TEXT_HINT = 0x00000800;
+
+ /**
+ * Indicates that the 'mime-type' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_MIME_TYPE = 0x00001000;
+
+ /**
+ * Indicates that the 'link-count' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_LINK_COUNT = 0x00002000;
+
+ /**
+ * Indicates that the 'untranslated-name' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_UNTRANSLATED_NAME = 0x00004000;
+
+ /**
+ * Indicates that the 'ctime' field is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_CTIME = 0x00008000;
+
+ /**
+ * Indicates that the 'extended-count' field (and probablby some
+ * 'extensions') is present.
+ */
+ public static final int SSH_FILEXFER_ATTR_EXTENDED = 0x80000000;
+}
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribPermissions.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribPermissions.java
new file mode 100644
index 0000000..558aa6f
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribPermissions.java
@@ -0,0 +1,32 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * Permissions for the 'permissions' field in the SFTP ATTRS data type.
+ * <p>
+ * "<i>The 'permissions' field contains a bit mask specifying file permissions.
+ * These permissions correspond to the st_mode field of the stat structure
+ * defined by POSIX [IEEE.1003-1.1996].</i>"
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: AttribPermissions.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ *
+ */
+public class AttribPermissions
+{
+ /* Octal values! */
+
+ public static final int S_IRUSR = 0400;
+ public static final int S_IWUSR = 0200;
+ public static final int S_IXUSR = 0100;
+ public static final int S_IRGRP = 0040;
+ public static final int S_IWGRP = 0020;
+ public static final int S_IXGRP = 0010;
+ public static final int S_IROTH = 0004;
+ public static final int S_IWOTH = 0002;
+ public static final int S_IXOTH = 0001;
+ public static final int S_ISUID = 04000;
+ public static final int S_ISGID = 02000;
+ public static final int S_ISVTX = 01000;
+}
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribTypes.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribTypes.java
new file mode 100644
index 0000000..e2f4169
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/AttribTypes.java
@@ -0,0 +1,28 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * Types for the 'type' field in the SFTP ATTRS data type.
+ * <p>
+ * "<i>On a POSIX system, these values would be derived from the mode field
+ * of the stat structure. SPECIAL should be used for files that are of
+ * a known type which cannot be expressed in the protocol. UNKNOWN
+ * should be used if the type is not known.</i>"
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: AttribTypes.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ *
+ */
+public class AttribTypes
+{
+ public static final int SSH_FILEXFER_TYPE_REGULAR = 1;
+ public static final int SSH_FILEXFER_TYPE_DIRECTORY = 2;
+ public static final int SSH_FILEXFER_TYPE_SYMLINK = 3;
+ public static final int SSH_FILEXFER_TYPE_SPECIAL = 4;
+ public static final int SSH_FILEXFER_TYPE_UNKNOWN = 5;
+ public static final int SSH_FILEXFER_TYPE_SOCKET = 6;
+ public static final int SSH_FILEXFER_TYPE_CHAR_DEVICE = 7;
+ public static final int SSH_FILEXFER_TYPE_BLOCK_DEVICE = 8;
+ public static final int SSH_FILEXFER_TYPE_FIFO = 9;
+}
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/ErrorCodes.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/ErrorCodes.java
new file mode 100644
index 0000000..7317a00
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/ErrorCodes.java
@@ -0,0 +1,104 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * SFTP Error Codes
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: ErrorCodes.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ *
+ */
+public class ErrorCodes
+{
+ public static final int SSH_FX_OK = 0;
+ public static final int SSH_FX_EOF = 1;
+ public static final int SSH_FX_NO_SUCH_FILE = 2;
+ public static final int SSH_FX_PERMISSION_DENIED = 3;
+ public static final int SSH_FX_FAILURE = 4;
+ public static final int SSH_FX_BAD_MESSAGE = 5;
+ public static final int SSH_FX_NO_CONNECTION = 6;
+ public static final int SSH_FX_CONNECTION_LOST = 7;
+ public static final int SSH_FX_OP_UNSUPPORTED = 8;
+ public static final int SSH_FX_INVALID_HANDLE = 9;
+ public static final int SSH_FX_NO_SUCH_PATH = 10;
+ public static final int SSH_FX_FILE_ALREADY_EXISTS = 11;
+ public static final int SSH_FX_WRITE_PROTECT = 12;
+ public static final int SSH_FX_NO_MEDIA = 13;
+ public static final int SSH_FX_NO_SPACE_ON_FILESYSTEM = 14;
+ public static final int SSH_FX_QUOTA_EXCEEDED = 15;
+ public static final int SSH_FX_UNKNOWN_PRINCIPAL = 16;
+ public static final int SSH_FX_LOCK_CONFLICT = 17;
+ public static final int SSH_FX_DIR_NOT_EMPTY = 18;
+ public static final int SSH_FX_NOT_A_DIRECTORY = 19;
+ public static final int SSH_FX_INVALID_FILENAME = 20;
+ public static final int SSH_FX_LINK_LOOP = 21;
+ public static final int SSH_FX_CANNOT_DELETE = 22;
+ public static final int SSH_FX_INVALID_PARAMETER = 23;
+ public static final int SSH_FX_FILE_IS_A_DIRECTORY = 24;
+ public static final int SSH_FX_BYTE_RANGE_LOCK_CONFLICT = 25;
+ public static final int SSH_FX_BYTE_RANGE_LOCK_REFUSED = 26;
+ public static final int SSH_FX_DELETE_PENDING = 27;
+ public static final int SSH_FX_FILE_CORRUPT = 28;
+ public static final int SSH_FX_OWNER_INVALID = 29;
+ public static final int SSH_FX_GROUP_INVALID = 30;
+ public static final int SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK = 31;
+
+ private static final String[][] messages = {
+
+ { "SSH_FX_OK", "Indicates successful completion of the operation." },
+ { "SSH_FX_EOF",
+ "An attempt to read past the end-of-file was made; or, there are no more directory entries to return." },
+ { "SSH_FX_NO_SUCH_FILE", "A reference was made to a file which does not exist." },
+ { "SSH_FX_PERMISSION_DENIED", "The user does not have sufficient permissions to perform the operation." },
+ { "SSH_FX_FAILURE", "An error occurred, but no specific error code exists to describe the failure." },
+ { "SSH_FX_BAD_MESSAGE", "A badly formatted packet or other SFTP protocol incompatibility was detected." },
+ { "SSH_FX_NO_CONNECTION", "There is no connection to the server." },
+ { "SSH_FX_CONNECTION_LOST", "The connection to the server was lost." },
+ { "SSH_FX_OP_UNSUPPORTED",
+ "An attempted operation could not be completed by the server because the server does not support the operation." },
+ { "SSH_FX_INVALID_HANDLE", "The handle value was invalid." },
+ { "SSH_FX_NO_SUCH_PATH", "The file path does not exist or is invalid." },
+ { "SSH_FX_FILE_ALREADY_EXISTS", "The file already exists." },
+ { "SSH_FX_WRITE_PROTECT", "The file is on read-only media, or the media is write protected." },
+ { "SSH_FX_NO_MEDIA",
+ "The requested operation cannot be completed because there is no media available in the drive." },
+ { "SSH_FX_NO_SPACE_ON_FILESYSTEM",
+ "The requested operation cannot be completed because there is insufficient free space on the filesystem." },
+ { "SSH_FX_QUOTA_EXCEEDED",
+ "The operation cannot be completed because it would exceed the user's storage quota." },
+ {
+ "SSH_FX_UNKNOWN_PRINCIPAL",
+ "A principal referenced by the request (either the 'owner', 'group', or 'who' field of an ACL), was unknown. The error specific data contains the problematic names." },
+ { "SSH_FX_LOCK_CONFLICT", "The file could not be opened because it is locked by another process." },
+ { "SSH_FX_DIR_NOT_EMPTY", "The directory is not empty." },
+ { "SSH_FX_NOT_A_DIRECTORY", "The specified file is not a directory." },
+ { "SSH_FX_INVALID_FILENAME", "The filename is not valid." },
+ { "SSH_FX_LINK_LOOP",
+ "Too many symbolic links encountered or, an SSH_FXF_NOFOLLOW open encountered a symbolic link as the final component." },
+ { "SSH_FX_CANNOT_DELETE",
+ "The file cannot be deleted. One possible reason is that the advisory READONLY attribute-bit is set." },
+ { "SSH_FX_INVALID_PARAMETER",
+ "One of the parameters was out of range, or the parameters specified cannot be used together." },
+ { "SSH_FX_FILE_IS_A_DIRECTORY",
+ "The specified file was a directory in a context where a directory cannot be used." },
+ { "SSH_FX_BYTE_RANGE_LOCK_CONFLICT",
+ " A read or write operation failed because another process's mandatory byte-range lock overlaps with the request." },
+ { "SSH_FX_BYTE_RANGE_LOCK_REFUSED", "A request for a byte range lock was refused." },
+ { "SSH_FX_DELETE_PENDING", "An operation was attempted on a file for which a delete operation is pending." },
+ { "SSH_FX_FILE_CORRUPT", "The file is corrupt; an filesystem integrity check should be run." },
+ { "SSH_FX_OWNER_INVALID", "The principal specified can not be assigned as an owner of a file." },
+ { "SSH_FX_GROUP_INVALID", "The principal specified can not be assigned as the primary group of a file." },
+ { "SSH_FX_NO_MATCHING_BYTE_RANGE_LOCK",
+ "The requested operation could not be completed because the specifed byte range lock has not been granted." },
+
+ };
+
+ public static final String[] getDescription(int errorCode)
+ {
+ if ((errorCode < 0) || (errorCode >= messages.length))
+ return null;
+
+ return messages[errorCode];
+ }
+}
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/OpenFlags.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/OpenFlags.java
new file mode 100644
index 0000000..b2979b9
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/OpenFlags.java
@@ -0,0 +1,223 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * SFTP Open Flags.
+ *
+ * The following table is provided to assist in mapping POSIX semantics
+ * to equivalent SFTP file open parameters:
+ * <p>
+ * TODO: This comment should be moved to the open method.
+ * <p>
+ * <ul>
+ * <li>O_RDONLY
+ * <ul><li>desired-access = READ_DATA | READ_ATTRIBUTES</li></ul>
+ * </li>
+ * </ul>
+ * <ul>
+ * <li>O_WRONLY
+ * <ul><li>desired-access = WRITE_DATA | WRITE_ATTRIBUTES</li></ul>
+ * </li>
+ * </ul>
+ * <ul>
+ * <li>O_RDWR
+ * <ul><li>desired-access = READ_DATA | READ_ATTRIBUTES | WRITE_DATA | WRITE_ATTRIBUTES</li></ul>
+ * </li>
+ * </ul>
+ * <ul>
+ * <li>O_APPEND
+ * <ul>
+ * <li>desired-access = WRITE_DATA | WRITE_ATTRIBUTES | APPEND_DATA</li>
+ * <li>flags = SSH_FXF_ACCESS_APPEND_DATA and or SSH_FXF_ACCESS_APPEND_DATA_ATOMIC</li>
+ * </ul>
+ * </li>
+ * </ul>
+ * <ul>
+ * <li>O_CREAT
+ * <ul>
+ * <li>flags = SSH_FXF_OPEN_OR_CREATE</li>
+ * </ul>
+ * </li>
+ * </ul>
+ * <ul>
+ * <li>O_TRUNC
+ * <ul>
+ * <li>flags = SSH_FXF_TRUNCATE_EXISTING</li>
+ * </ul>
+ * </li>
+ * </ul>
+ * <ul>
+ * <li>O_TRUNC|O_CREATE
+ * <ul>
+ * <li>flags = SSH_FXF_CREATE_TRUNCATE</li>
+ * </ul>
+ * </li>
+ * </ul>
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: OpenFlags.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ */
+public class OpenFlags
+{
+ /**
+ * Disposition is a 3 bit field that controls how the file is opened.
+ * The server MUST support these bits (possible enumaration values:
+ * SSH_FXF_CREATE_NEW, SSH_FXF_CREATE_TRUNCATE, SSH_FXF_OPEN_EXISTING,
+ * SSH_FXF_OPEN_OR_CREATE or SSH_FXF_TRUNCATE_EXISTING).
+ */
+ public static final int SSH_FXF_ACCESS_DISPOSITION = 0x00000007;
+
+ /**
+ * A new file is created; if the file already exists, the server
+ * MUST return status SSH_FX_FILE_ALREADY_EXISTS.
+ */
+ public static final int SSH_FXF_CREATE_NEW = 0x00000000;
+
+ /**
+ * A new file is created; if the file already exists, it is opened
+ * and truncated.
+ */
+ public static final int SSH_FXF_CREATE_TRUNCATE = 0x00000001;
+
+ /**
+ * An existing file is opened. If the file does not exist, the
+ * server MUST return SSH_FX_NO_SUCH_FILE. If a directory in the
+ * path does not exist, the server SHOULD return
+ * SSH_FX_NO_SUCH_PATH. It is also acceptable if the server
+ * returns SSH_FX_NO_SUCH_FILE in this case.
+ */
+ public static final int SSH_FXF_OPEN_EXISTING = 0x00000002;
+
+ /**
+ * If the file exists, it is opened. If the file does not exist,
+ * it is created.
+ */
+ public static final int SSH_FXF_OPEN_OR_CREATE = 0x00000003;
+
+ /**
+ * An existing file is opened and truncated. If the file does not
+ * exist, the server MUST return the same error codes as defined
+ * for SSH_FXF_OPEN_EXISTING.
+ */
+ public static final int SSH_FXF_TRUNCATE_EXISTING = 0x00000004;
+
+ /**
+ * Data is always written at the end of the file. The offset field
+ * of the SSH_FXP_WRITE requests are ignored.
+ * <p>
+ * Data is not required to be appended atomically. This means that
+ * if multiple writers attempt to append data simultaneously, data
+ * from the first may be lost. However, data MAY be appended
+ * atomically.
+ */
+ public static final int SSH_FXF_ACCESS_APPEND_DATA = 0x00000008;
+
+ /**
+ * Data is always written at the end of the file. The offset field
+ * of the SSH_FXP_WRITE requests are ignored.
+ * <p>
+ * Data MUST be written atomically so that there is no chance that
+ * multiple appenders can collide and result in data being lost.
+ * <p>
+ * If both append flags are specified, the server SHOULD use atomic
+ * append if it is available, but SHOULD use non-atomic appends
+ * otherwise. The server SHOULD NOT fail the request in this case.
+ */
+ public static final int SSH_FXF_ACCESS_APPEND_DATA_ATOMIC = 0x00000010;
+
+ /**
+ * Indicates that the server should treat the file as text and
+ * convert it to the canonical newline convention in use.
+ * (See Determining Server Newline Convention in section 5.3 in the
+ * SFTP standard draft).
+ * <p>
+ * When a file is opened with this flag, the offset field in the read
+ * and write functions is ignored.
+ * <p>
+ * Servers MUST process multiple, parallel reads and writes correctly
+ * in this mode. Naturally, it is permissible for them to do this by
+ * serializing the requests.
+ * <p>
+ * Clients SHOULD use the SSH_FXF_ACCESS_APPEND_DATA flag to append
+ * data to a text file rather then using write with a calculated offset.
+ */
+ public static final int SSH_FXF_ACCESS_TEXT_MODE = 0x00000020;
+
+ /**
+ * The server MUST guarantee that no other handle has been opened
+ * with ACE4_READ_DATA access, and that no other handle will be
+ * opened with ACE4_READ_DATA access until the client closes the
+ * handle. (This MUST apply both to other clients and to other
+ * processes on the server.)
+ * <p>
+ * If there is a conflicting lock the server MUST return
+ * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
+ * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
+ * <p>
+ * Other handles MAY be opened for ACE4_WRITE_DATA or any other
+ * combination of accesses, as long as ACE4_READ_DATA is not included
+ * in the mask.
+ */
+ public static final int SSH_FXF_ACCESS_BLOCK_READ = 0x00000040;
+
+ /**
+ * The server MUST guarantee that no other handle has been opened
+ * with ACE4_WRITE_DATA or ACE4_APPEND_DATA access, and that no other
+ * handle will be opened with ACE4_WRITE_DATA or ACE4_APPEND_DATA
+ * access until the client closes the handle. (This MUST apply both
+ * to other clients and to other processes on the server.)
+ * <p>
+ * If there is a conflicting lock the server MUST return
+ * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
+ * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
+ * <p>
+ * Other handles MAY be opened for ACE4_READ_DATA or any other
+ * combination of accesses, as long as neither ACE4_WRITE_DATA nor
+ * ACE4_APPEND_DATA are included in the mask.
+ */
+ public static final int SSH_FXF_ACCESS_BLOCK_WRITE = 0x00000080;
+
+ /**
+ * The server MUST guarantee that no other handle has been opened
+ * with ACE4_DELETE access, opened with the
+ * SSH_FXF_ACCESS_DELETE_ON_CLOSE flag set, and that no other handle
+ * will be opened with ACE4_DELETE access or with the
+ * SSH_FXF_ACCESS_DELETE_ON_CLOSE flag set, and that the file itself
+ * is not deleted in any other way until the client closes the handle.
+ * <p>
+ * If there is a conflicting lock the server MUST return
+ * SSH_FX_LOCK_CONFLICT. If the server cannot make the locking
+ * guarantee, it MUST return SSH_FX_OP_UNSUPPORTED.
+ */
+ public static final int SSH_FXF_ACCESS_BLOCK_DELETE = 0x00000100;
+
+ /**
+ * If this bit is set, the above BLOCK modes are advisory. In advisory
+ * mode, only other accesses that specify a BLOCK mode need be
+ * considered when determining whether the BLOCK can be granted,
+ * and the server need not prevent I/O operations that violate the
+ * block mode.
+ * <p>
+ * The server MAY perform mandatory locking even if the BLOCK_ADVISORY
+ * bit is set.
+ */
+ public static final int SSH_FXF_ACCESS_BLOCK_ADVISORY = 0x00000200;
+
+ /**
+ * If the final component of the path is a symlink, then the open
+ * MUST fail, and the error SSH_FX_LINK_LOOP MUST be returned.
+ */
+ public static final int SSH_FXF_ACCESS_NOFOLLOW = 0x00000400;
+
+ /**
+ * The file should be deleted when the last handle to it is closed.
+ * (The last handle may not be an sftp-handle.) This MAY be emulated
+ * by a server if the OS doesn't support it by deleting the file when
+ * this handle is closed.
+ * <p>
+ * It is implementation specific whether the directory entry is
+ * removed immediately or when the handle is closed.
+ */
+ public static final int SSH_FXF_ACCESS_DELETE_ON_CLOSE = 0x00000800;
+}
diff --git a/sshlib/src/main/java/com/trilead/ssh2/sftp/Packet.java b/sshlib/src/main/java/com/trilead/ssh2/sftp/Packet.java
new file mode 100644
index 0000000..444af90
--- /dev/null
+++ b/sshlib/src/main/java/com/trilead/ssh2/sftp/Packet.java
@@ -0,0 +1,43 @@
+
+package com.trilead.ssh2.sftp;
+
+/**
+ *
+ * SFTP Paket Types
+ *
+ * @author Christian Plattner, plattner@trilead.com
+ * @version $Id: Packet.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
+ *
+ */
+public class Packet
+{
+ public static final int SSH_FXP_INIT = 1;
+ public static final int SSH_FXP_VERSION = 2;
+ public static final int SSH_FXP_OPEN = 3;
+ public static final int SSH_FXP_CLOSE = 4;
+ public static final int SSH_FXP_READ = 5;
+ public static final int SSH_FXP_WRITE = 6;
+ public static final int SSH_FXP_LSTAT = 7;
+ public static final int SSH_FXP_FSTAT = 8;
+ public static final int SSH_FXP_SETSTAT = 9;
+ public static final int SSH_FXP_FSETSTAT = 10;
+ public static final int SSH_FXP_OPENDIR = 11;
+ public static final int SSH_FXP_READDIR = 12;
+ public static final int SSH_FXP_REMOVE = 13;
+ public static final int SSH_FXP_MKDIR = 14;
+ public static final int SSH_FXP_RMDIR = 15;
+ public static final int SSH_FXP_REALPATH = 16;
+ public static final int SSH_FXP_STAT = 17;
+ public static final int SSH_FXP_RENAME = 18;
+ public static final int SSH_FXP_READLINK = 19;
+ public static final int SSH_FXP_SYMLINK = 20;
+
+ public static final int SSH_FXP_STATUS = 101;
+ public static final int SSH_FXP_HANDLE = 102;
+ public static final int SSH_FXP_DATA = 103;
+ public static final int SSH_FXP_NAME = 104;
+ public static final int SSH_FXP_ATTRS = 105;
+
+ public static final int SSH_FXP_EXTENDED = 200;
+ public static final int SSH_FXP_EXTENDED_REPLY = 201;
+}