sftp.h   sftp.h 
skipping to change at line 28 skipping to change at line 28
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA. * MA 02111-1307, USA.
*/ */
/** /**
* @file sftp.h * @file sftp.h
* *
* @brief SFTP handling functions * @brief SFTP handling functions
* *
* SFTP commands are channeled by the ssh sftp subsystem. Every packet is * SFTP commands are channeled by the ssh sftp subsystem. Every packet is
* sent/read using a SFTP_PACKET type structure. Related to these packets, * sent/read using a sftp_packet type structure. Related to these packets,
* most of the server answers are messages having an ID and a message * most of the server answers are messages having an ID and a message
* specific part. It is described by SFTP_MESSAGE when reading a message, * specific part. It is described by sftp_message when reading a message,
* the sftp system puts it into the queue, so the process having asked for * the sftp system puts it into the queue, so the process having asked for
* it can fetch it, while continuing to read for other messages (it is * it can fetch it, while continuing to read for other messages (it is
* inspecified in which order messages may be sent back to the client * unspecified in which order messages may be sent back to the client
* *
* @defgroup ssh_sftp SFTP Functions * @defgroup ssh_sftp SFTP Functions
* @{ * @{
*/ */
#ifndef SFTP_H #ifndef SFTP_H
#define SFTP_H #define SFTP_H
#include <libssh/libssh.h>
#include <sys/types.h>
#include "libssh.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef __GNUC__
#define SFTP_DEPRECATED __attribute__ ((deprecated))
#else
#define SFTP_DEPRECATED
#endif
#ifdef _WIN32 #ifdef _WIN32
#ifndef uid_t #ifndef uid_t
typedef long uid_t; typedef uint32_t uid_t;
#endif /* uid_t */ #endif /* uid_t */
#ifndef gid_t #ifndef gid_t
typedef long gid_t; typedef uint32_t gid_t;
#endif /* gid_t */ #endif /* gid_t */
#ifdef _MSC_VER
#ifndef ssize_t
typedef _W64 SSIZE_T ssize_t;
#endif /* ssize_t */
#endif /* _MSC_VER */
#endif /* _WIN32 */ #endif /* _WIN32 */
typedef struct sftp_session_struct { typedef struct sftp_attributes_struct* sftp_attributes;
SSH_SESSION *session; typedef struct sftp_client_message_struct* sftp_client_message;
CHANNEL *channel; typedef struct sftp_dir_struct* sftp_dir;
typedef struct sftp_ext_struct *sftp_ext;
typedef struct sftp_file_struct* sftp_file;
typedef struct sftp_message_struct* sftp_message;
typedef struct sftp_packet_struct* sftp_packet;
typedef struct sftp_request_queue_struct* sftp_request_queue;
typedef struct sftp_session_struct* sftp_session;
typedef struct sftp_status_message_struct* sftp_status_message;
typedef struct sftp_statvfs_struct* sftp_statvfs_t;
struct sftp_session_struct {
ssh_session session;
ssh_channel channel;
int server_version; int server_version;
int client_version; int client_version;
int version; int version;
struct request_queue *queue; sftp_request_queue queue;
u32 id_counter; uint32_t id_counter;
int errnum; int errnum;
void **handles; void **handles;
} SFTP_SESSION ; sftp_ext ext;
};
typedef struct { struct sftp_packet_struct {
SFTP_SESSION *sftp; sftp_session sftp;
u8 type; uint8_t type;
BUFFER *payload; ssh_buffer payload;
} SFTP_PACKET; };
/* file handler */ /* file handler */
typedef struct sftp_file{ struct sftp_file_struct {
SFTP_SESSION *sftp; sftp_session sftp;
char *name; char *name;
u64 offset; uint64_t offset;
STRING *handle; ssh_string handle;
int eof; int eof;
int nonblocking; int nonblocking;
} SFTP_FILE ; };
typedef struct sftp_dir { struct sftp_dir_struct {
SFTP_SESSION *sftp; sftp_session sftp;
char *name; char *name;
STRING *handle; /* handle to directory */ ssh_string handle; /* handle to directory */
BUFFER *buffer; /* contains raw attributes from server which haven't be ssh_buffer buffer; /* contains raw attributes from server which haven't
en parsed */ been parsed */
u32 count; /* counts the number of following attributes structures into uint32_t count; /* counts the number of following attributes structures
buffer */ into buffer */
int eof; /* end of directory listing */ int eof; /* end of directory listing */
} SFTP_DIR; };
typedef struct { struct sftp_message_struct {
SFTP_SESSION *sftp; sftp_session sftp;
u8 packet_type; uint8_t packet_type;
BUFFER *payload; ssh_buffer payload;
u32 id; uint32_t id;
} SFTP_MESSAGE; };
/* this is a bunch of all data that could be into a message */ /* this is a bunch of all data that could be into a message */
typedef struct sftp_client_message{ struct sftp_client_message_struct {
SFTP_SESSION *sftp; sftp_session sftp;
u8 type; uint8_t type;
u32 id; uint32_t id;
char *filename; /* can be "path" */ char *filename; /* can be "path" */
u32 flags; uint32_t flags;
struct sftp_attributes *attr; sftp_attributes attr;
STRING *handle; ssh_string handle;
u64 offset; uint64_t offset;
u32 len; uint32_t len;
int attr_num; int attr_num;
BUFFER *attrbuf; /* used by sftp_reply_attrs */ ssh_buffer attrbuf; /* used by sftp_reply_attrs */
STRING *data; /* can be newpath of rename() */ ssh_string data; /* can be newpath of rename() */
} SFTP_CLIENT_MESSAGE; };
typedef struct request_queue{ struct sftp_request_queue_struct {
struct request_queue *next; sftp_request_queue next;
SFTP_MESSAGE *message; sftp_message message;
} REQUEST_QUEUE; };
/* SSH_FXP_MESSAGE described into .7 page 26 */ /* SSH_FXP_MESSAGE described into .7 page 26 */
typedef struct { struct sftp_status_message_struct {
u32 id; uint32_t id;
u32 status; uint32_t status;
STRING *error; ssh_string error;
STRING *lang; ssh_string lang;
char *errormsg; char *errormsg;
char *langmsg; char *langmsg;
} STATUS_MESSAGE; };
/* don't worry much of these aren't really used */ /* don't worry much of these aren't really used */
typedef struct sftp_attributes{ struct sftp_attributes_struct {
char *name; char *name;
char *longname; /* some weird stuff */ char *longname; /* some weird stuff */
u32 flags; uint32_t flags;
u8 type; uint8_t type;
u64 size; uint64_t size;
u32 uid; uint32_t uid;
u32 gid; uint32_t gid;
char *owner; char *owner;
char *group; char *group;
u32 permissions; uint32_t permissions;
u64 atime64; uint64_t atime64;
u32 atime; uint32_t atime;
u32 atime_nseconds; uint32_t atime_nseconds;
u64 createtime; uint64_t createtime;
u32 createtime_nseconds; uint32_t createtime_nseconds;
u64 mtime64; uint64_t mtime64;
u32 mtime; uint32_t mtime;
u32 mtime_nseconds; uint32_t mtime_nseconds;
STRING *acl; ssh_string acl;
u32 extended_count; uint32_t extended_count;
STRING *extended_type; ssh_string extended_type;
STRING *extended_data; ssh_string extended_data;
} SFTP_ATTRIBUTES; };
struct sftp_statvfs_struct {
uint64_t f_bsize; /* file system block size */
uint64_t f_frsize; /* fundamental fs block size */
uint64_t f_blocks; /* number of blocks (unit f_frsize) */
uint64_t f_bfree; /* free blocks in file system */
uint64_t f_bavail; /* free blocks for non-root */
uint64_t f_files; /* total file inodes */
uint64_t f_ffree; /* free file inodes */
uint64_t f_favail; /* free file inodes for to non-root */
uint64_t f_fsid; /* file system id */
uint64_t f_flag; /* bit mask of f_flag values */
uint64_t f_namemax; /* maximum filename length */
};
#define LIBSFTP_VERSION 3 #define LIBSFTP_VERSION 3
/** /**
* @brief Start a new sftp session. * @brief Start a new sftp session.
* *
* @param session The ssh session to use. * @param session The ssh session to use.
* *
* @return A new sftp session or NULL on error. * @return A new sftp session or NULL on error.
*/ */
SFTP_SESSION *sftp_new(SSH_SESSION *session); LIBSSH_API sftp_session sftp_new(ssh_session session);
/** /**
* @brief Close and deallocate a sftp session. * @brief Close and deallocate a sftp session.
* *
* @param sftp The sftp session handle to free. * @param sftp The sftp session handle to free.
*/ */
void sftp_free(SFTP_SESSION *sftp); LIBSSH_API void sftp_free(sftp_session sftp);
/** /**
* @brief Initialize the sftp session with the server. * @brief Initialize the sftp session with the server.
* *
* @param sftp The sftp session to initialize. * @param sftp The sftp session to initialize.
* *
* @return 0 on success, < 0 on error with ssh error set. * @return 0 on success, < 0 on error with ssh error set.
*/ */
int sftp_init(SFTP_SESSION *sftp); LIBSSH_API int sftp_init(sftp_session sftp);
/** /**
* @brief Get the last sftp error. * @brief Get the last sftp error.
* *
* Use this function to get the latest error set by a posix like sftp funct ion. * Use this function to get the latest error set by a posix like sftp funct ion.
* *
* @param sftp The sftp session where the error is saved. * @param sftp The sftp session where the error is saved.
* *
* @return The saved error (see server responses), < 0 if an e rror * @return The saved error (see server responses), < 0 if an e rror
* in the function occured. * in the function occured.
*/ */
int sftp_get_error(SFTP_SESSION *sftp); LIBSSH_API int sftp_get_error(sftp_session sftp);
/** /**
* @brief Open a directory used to obtain directory entries. * @brief Get the count of extensions provided by the server.
*
* @param sftp The sftp session to use.
*
* @return The count of extensions provided by the server, 0 on error or
* not available.
*/
LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp);
/**
* @brief Get the name of the extension provided by the server.
*
* @param sftp The sftp session to use.
*
* @param indexn The index number of the extension name you want.
*
* @return The name of the extension.
*/
LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned
int indexn);
/**
* @brief Get the data of the extension provided by the server.
*
* This is normally the version number of the extension.
*
* @param sftp The sftp session to use.
* *
* @param indexn The index number of the extension data you want.
*
* @return The data of the extension.
*/
LIBSSH_API const char *sftp_extensions_get_data(sftp_session sftp, unsigned
int indexn);
/**
* @brief Check if the given extension is supported.
*
* @param sftp The sftp session to use.
*
* @param name The name of the extension.
*
* @param data The data of the extension.
*
* @return 1 if supported, 0 if not.
*
* Example:
*
* @code
* sftp_extension_supported(sftp, "statvfs@openssh.com", "2");
* @endcode
*/
LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name
,
const char *data);
/**
* @brief Open a directory used to obtain directory entries.
* @param session The sftp session handle to open the directory. * @param session The sftp session handle to open the directory.
* @param path The path of the directory to open. * @param path The path of the directory to open.
* *
* @return A sftp directory handle or NULL on error with ssh a nd * @return A sftp directory handle or NULL on error with ssh a nd
* sftp error set. * sftp error set.
* *
* @see sftp_readdir * @see sftp_readdir
* @see sftp_closedir * @see sftp_closedir
*/ */
SFTP_DIR *sftp_opendir(SFTP_SESSION *session, const char *path); LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path);
/** /**
* @brief Get a single file attributes structure of a directory. * @brief Get a single file attributes structure of a directory.
* *
* @param session The sftp session handle to read the directory entry. * @param session The sftp session handle to read the directory entry.
* @param dir The opened sftp directory handle to read from. * @param dir The opened sftp directory handle to read from.
* *
* @return A file attribute structure or NULL at the end of the * @return A file attribute structure or NULL at the end of the
* directory. * directory.
* *
* @see sftp_opendir() * @see sftp_opendir()
* @see sftp_attribute_free() * @see sftp_attribute_free()
* @see sftp_closedir() * @see sftp_closedir()
*/ */
SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *session, SFTP_DIR *dir); LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir) ;
/** /**
* @brief Tell if the directory has reached EOF (End Of File). * @brief Tell if the directory has reached EOF (End Of File).
* *
* @param dir The sftp directory handle. * @param dir The sftp directory handle.
* *
* @return 1 if the directory is EOF, 0 if not. * @return 1 if the directory is EOF, 0 if not.
* *
* @see sftp_readdir() * @see sftp_readdir()
*/ */
int sftp_dir_eof(SFTP_DIR *dir); LIBSSH_API int sftp_dir_eof(sftp_dir dir);
/** /**
* @brief Get information about a file or directory. * @brief Get information about a file or directory.
* *
* @param session The sftp session handle. * @param session The sftp session handle.
* @param path The path to the file or directory to obtain the * @param path The path to the file or directory to obtain the
* information. * information.
* *
* @return The sftp attributes structure of the file or direct ory, * @return The sftp attributes structure of the file or direct ory,
* NULL on error with ssh and sftp error set. * NULL on error with ssh and sftp error set.
*/ */
SFTP_ATTRIBUTES *sftp_stat(SFTP_SESSION *session, const char *path); LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path );
/** /**
* @brief Get information about a file or directory. * @brief Get information about a file or directory.
* *
* Identical to sftp_stat, but if the file or directory is a symbolic link, * Identical to sftp_stat, but if the file or directory is a symbolic link,
* then the link itself is stated, not the file that it refers to. * then the link itself is stated, not the file that it refers to.
* *
* @param session The sftp session handle. * @param session The sftp session handle.
* @param path The path to the file or directory to obtain the * @param path The path to the file or directory to obtain the
* information. * information.
* *
* @return The sftp attributes structure of the file or direct ory, * @return The sftp attributes structure of the file or direct ory,
* NULL on error with ssh and sftp error set. * NULL on error with ssh and sftp error set.
*/ */
SFTP_ATTRIBUTES *sftp_lstat(SFTP_SESSION *session, const char *path); LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *pat h);
/** /**
* @brief Get information about a file or directory from a file handle. * @brief Get information about a file or directory from a file handle.
* *
* @param file The sftp file handle to get the stat information. * @param file The sftp file handle to get the stat information.
* *
* @return The sftp attributes structure of the file or direct ory, * @return The sftp attributes structure of the file or direct ory,
* NULL on error with ssh and sftp error set. * NULL on error with ssh and sftp error set.
*/ */
SFTP_ATTRIBUTES *sftp_fstat(SFTP_FILE *file); LIBSSH_API sftp_attributes sftp_fstat(sftp_file file);
/** /**
* @brief Free a sftp attribute structure. * @brief Free a sftp attribute structure.
* *
* @param file The sftp attribute structure to free. * @param file The sftp attribute structure to free.
*/ */
void sftp_attributes_free(SFTP_ATTRIBUTES *file); LIBSSH_API void sftp_attributes_free(sftp_attributes file);
/** /**
* @brief Close a directory handle opened by sftp_opendir(). * @brief Close a directory handle opened by sftp_opendir().
* *
* @param dir The sftp directory handle to close. * @param dir The sftp directory handle to close.
* *
* @return Returns SSH_NO_ERROR or SSH_ERROR if an error occur ed. * @return Returns SSH_NO_ERROR or SSH_ERROR if an error occur ed.
*/ */
int sftp_closedir(SFTP_DIR *dir); LIBSSH_API int sftp_closedir(sftp_dir dir);
/**
* @deprecated Use sftp_closedir() instead.
*/
int sftp_dir_close(SFTP_DIR *dir) SFTP_DEPRECATED;
/** /**
* @brief Close an open file handle. * @brief Close an open file handle.
* *
* @param file The open sftp file handle to close. * @param file The open sftp file handle to close.
* *
* @return Returns SSH_NO_ERROR or SSH_ERROR if an error occur ed. * @return Returns SSH_NO_ERROR or SSH_ERROR if an error occur ed.
* *
* @see sftp_open() * @see sftp_open()
*/ */
int sftp_close(SFTP_FILE *file); LIBSSH_API int sftp_close(sftp_file file);
/**
* @deprecated Use sftp_close() instead.
*/
int sftp_file_close(SFTP_FILE *file) SFTP_DEPRECATED;
/** /**
* @brief Open a file on the server. * @brief Open a file on the server.
* *
* @param session The sftp session handle. * @param session The sftp session handle.
* *
* @param file The file to be opened. * @param file The file to be opened.
* *
* @param access Is one of O_RDONLY, O_WRONLY or O_RDWR which reques t * @param accesstype Is one of O_RDONLY, O_WRONLY or O_RDWR which re quest
* opening the file read-only,write-only or read/wr ite. * opening the file read-only,write-only or read/wr ite.
* Acesss may also be bitwise-or'd with one or more o f * Acesss may also be bitwise-or'd with one or more o f
* the following: * the following:
* O_CREAT - If the file does not exist it will be * O_CREAT - If the file does not exist it will be
* created. * created.
* O_EXCL - When used with O_CREAT, if the file alrea dy * O_EXCL - When used with O_CREAT, if the file alrea dy
* exists it is an error and the open will fail. * exists it is an error and the open will fail.
* O_TRUNC - If the file already exists it will be * O_TRUNC - If the file already exists it will be
* truncated. * truncated.
* *
* @param mode Mode specifies the permissions to use if a new file is * @param mode Mode specifies the permissions to use if a new file is
* created. It is modified by the process's umask in * created. It is modified by the process's umask in
* the usual way: The permissions of the created file are * the usual way: The permissions of the created file are
* (mode & ~umask) * (mode & ~umask)
* *
* @return A sftp file handle, NULL on error with ssh and sftp * @return A sftp file handle, NULL on error with ssh and sftp
* error set. * error set.
*/ */
SFTP_FILE *sftp_open(SFTP_SESSION *session, const char *file, int flags, LIBSSH_API sftp_file sftp_open(sftp_session session, const char *file, int accesstype,
mode_t mode); mode_t mode);
void sftp_file_set_nonblocking(SFTP_FILE *handle); LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle);
void sftp_file_set_blocking(SFTP_FILE *handle); LIBSSH_API void sftp_file_set_blocking(sftp_file handle);
/** /**
* @brief Read from a file using an opened sftp file handle. * @brief Read from a file using an opened sftp file handle.
* *
* @param file The opened sftp file handle to be read from. * @param file The opened sftp file handle to be read from.
* *
* @param buf Pointer to buffer to recieve read data. * @param buf Pointer to buffer to recieve read data.
* *
* @param count Size of the buffer in bytes. * @param count Size of the buffer in bytes.
* *
* @return Number of bytes written, < 0 on error with ssh and sftp * @return Number of bytes written, < 0 on error with ssh and sftp
* error set. * error set.
*/ */
ssize_t sftp_read(SFTP_FILE *file, void *buf, size_t count); LIBSSH_API ssize_t sftp_read(sftp_file file, void *buf, size_t count);
/** /**
* @brief Start an asynchronous read from a file using an opened sftp file handle. * @brief Start an asynchronous read from a file using an opened sftp file handle.
* *
* Its goal is to avoid the slowdowns related to the request/response patte rn * Its goal is to avoid the slowdowns related to the request/response patte rn
* of a synchronous read. To do so, you must call 2 functions: * of a synchronous read. To do so, you must call 2 functions:
* *
* sftp_async_read_begin() and sftp_async_read(). * sftp_async_read_begin() and sftp_async_read().
* *
* The first step is to call sftp_async_read_begin(). This function returns a * The first step is to call sftp_async_read_begin(). This function returns a
skipping to change at line 393 skipping to change at line 467
* *
* @warning A call to sftp_async_read_begin() sends a request t o * @warning A call to sftp_async_read_begin() sends a request t o
* the server. When the server answers, libssh allocat es * the server. When the server answers, libssh allocat es
* memory to store it until sftp_async_read() is calle d. * memory to store it until sftp_async_read() is calle d.
* Not calling sftp_async_read() will lead to memory * Not calling sftp_async_read() will lead to memory
* leaks. * leaks.
* *
* @see sftp_async_read() * @see sftp_async_read()
* @see sftp_open() * @see sftp_open()
*/ */
int sftp_async_read_begin(SFTP_FILE *file, u32 len); LIBSSH_API int sftp_async_read_begin(sftp_file file, uint32_t len);
/** /**
* @brief Wait for an asynchronous read to complete and save the data. * @brief Wait for an asynchronous read to complete and save the data.
* *
* @param file The opened sftp file handle to be read from. * @param file The opened sftp file handle to be read from.
* *
* @param data Pointer to buffer to recieve read data. * @param data Pointer to buffer to recieve read data.
* *
* @param len Size of the buffer in bytes. It should be bigger or * @param len Size of the buffer in bytes. It should be bigger or
* equal to the length parameter of the * equal to the length parameter of the
skipping to change at line 418 skipping to change at line 492
* *
* @return Number of bytes read, 0 on EOF, SSH_ERROR if an err or * @return Number of bytes read, 0 on EOF, SSH_ERROR if an err or
* occured, SSH_AGAIN if the file is opened in nonbloc king * occured, SSH_AGAIN if the file is opened in nonbloc king
* mode and the request hasn't been executed yet. * mode and the request hasn't been executed yet.
* *
* @warning A call to this function with an invalid identifier * @warning A call to this function with an invalid identifier
* will never return. * will never return.
* *
* @see sftp_async_read_begin() * @see sftp_async_read_begin()
*/ */
int sftp_async_read(SFTP_FILE *file, void *data, u32 len, u32 id); LIBSSH_API int sftp_async_read(sftp_file file, void *data, uint32_t len, ui nt32_t id);
/** /**
* @brief Write to a file using an opened sftp file handle. * @brief Write to a file using an opened sftp file handle.
* *
* @param file Open sftp file handle to write to. * @param file Open sftp file handle to write to.
* *
* @param buf Pointer to buffer to write data. * @param buf Pointer to buffer to write data.
* *
* @param count Size of buffer in bytes. * @param count Size of buffer in bytes.
* *
* @return Number of bytes written, < 0 on error with ssh and sftp * @return Number of bytes written, < 0 on error with ssh and sftp
* error set. * error set.
* *
* @see sftp_open() * @see sftp_open()
* @see sftp_read() * @see sftp_read()
* @see sftp_close() * @see sftp_close()
*/ */
ssize_t sftp_write(SFTP_FILE *file, const void *buf, size_t count); LIBSSH_API ssize_t sftp_write(sftp_file file, const void *buf, size_t count );
/** /**
* @brief Seek to a specific location in a file. * @brief Seek to a specific location in a file.
* *
* @param file Open sftp file handle to seek in. * @param file Open sftp file handle to seek in.
* *
* @param new_offset Offset in bytes to seek. * @param new_offset Offset in bytes to seek.
* *
* @return 0 on success, < 0 on error. * @return 0 on success, < 0 on error.
*/ */
int sftp_seek(SFTP_FILE *file, u32 new_offset); LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset);
/** /**
* @brief Seek to a specific location in a file. This is the * @brief Seek to a specific location in a file. This is the
* 64bit version. * 64bit version.
* *
* @param file Open sftp file handle to seek in. * @param file Open sftp file handle to seek in.
* *
* @param new_offset Offset in bytes to seek. * @param new_offset Offset in bytes to seek.
* *
* @return 0 on success, < 0 on error. * @return 0 on success, < 0 on error.
*/ */
int sftp_seek64(SFTP_FILE *file, u64 new_offset); LIBSSH_API int sftp_seek64(sftp_file file, uint64_t new_offset);
/** /**
* @brief Report current byte position in file. * @brief Report current byte position in file.
* *
* @param file Open sftp file handle. * @param file Open sftp file handle.
* *
* @return The offset of the current byte relative to the begi nning * @return The offset of the current byte relative to the begi nning
* of the file associated with the file descriptor. < 0 on * of the file associated with the file descriptor. < 0 on
* error. * error.
*/ */
unsigned long sftp_tell(SFTP_FILE *file); LIBSSH_API unsigned long sftp_tell(sftp_file file);
/** /**
* @brief Report current byte position in file. * @brief Report current byte position in file.
* *
* @param file Open sftp file handle. * @param file Open sftp file handle.
* *
* @return The offset of the current byte relative to the begi nning * @return The offset of the current byte relative to the begi nning
* of the file associated with the file descriptor. < 0 on * of the file associated with the file descriptor. < 0 on
* error. * error.
*/ */
u64 sftp_tell64(SFTP_FILE *file); LIBSSH_API uint64_t sftp_tell64(sftp_file file);
/** /**
* @brief Rewinds the position of the file pointer to the beginning of the * @brief Rewinds the position of the file pointer to the beginning of the
* file. * file.
* *
* @param file Open sftp file handle. * @param file Open sftp file handle.
*/ */
void sftp_rewind(SFTP_FILE *file); LIBSSH_API void sftp_rewind(sftp_file file);
/**
* @deprecated Use sftp_unlink() instead.
*/
int sftp_rm(SFTP_SESSION *sftp, const char *file) SFTP_DEPRECATED;
/** /**
* @brief Unlink (delete) a file. * @brief Unlink (delete) a file.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param file The file to unlink/delete. * @param file The file to unlink/delete.
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_unlink(SFTP_SESSION *sftp, const char *file); LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file);
/** /**
* @brief Remove a directoy. * @brief Remove a directoy.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param directory The directory to remove. * @param directory The directory to remove.
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_rmdir(SFTP_SESSION *sftp, const char *directory); LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory);
/** /**
* @brief Create a directory. * @brief Create a directory.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param directory The directory to create. * @param directory The directory to create.
* *
* @param mode Specifies the permissions to use. It is modified by the * @param mode Specifies the permissions to use. It is modified by the
* process's umask in the usual way: * process's umask in the usual way:
* The permissions of the created file are (mode & ~um ask) * The permissions of the created file are (mode & ~um ask)
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_mkdir(SFTP_SESSION *sftp, const char *directory, mode_t mode); LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode);
/** /**
* @brief Rename or move a file or directory. * @brief Rename or move a file or directory.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param original The original url (source url) of file or directory to * @param original The original url (source url) of file or directory to
* be moved. * be moved.
* *
* @param newname The new url (destination url) of the file or direct ory * @param newname The new url (destination url) of the file or direct ory
* after the move. * after the move.
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_rename(SFTP_SESSION *sftp, const char *original, const char *newn ame); LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname);
/** /**
* @brief Set file attributes on a file, directory or symbolic link. * @brief Set file attributes on a file, directory or symbolic link.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param file The file which attributes should be changed. * @param file The file which attributes should be changed.
* *
* @param attr The file attributes structure with the attributes s et * @param attr The file attributes structure with the attributes s et
* which should be changed. * which should be changed.
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTES *att r); LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attri butes attr);
/** /**
* @brief Change the file owner and group * @brief Change the file owner and group
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param file The file which owner and group should be changed. * @param file The file which owner and group should be changed.
* *
* @param owner The new owner which should be set. * @param owner The new owner which should be set.
* *
* @param group The new group which should be set. * @param group The new group which should be set.
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_chown(SFTP_SESSION *sftp, const char *file, uid_t owner, gid_t gro up); LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group);
/** /**
* @brief Change permissions of a file * @brief Change permissions of a file
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param file The file which owner and group should be changed. * @param file The file which owner and group should be changed.
* *
* @param mode Specifies the permissions to use. It is modified by the * @param mode Specifies the permissions to use. It is modified by the
* process's umask in the usual way: * process's umask in the usual way:
* The permissions of the created file are (mode & ~um ask) * The permissions of the created file are (mode & ~um ask)
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_chmod(SFTP_SESSION *sftp, const char *file, mode_t mode); LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode) ;
/** /**
* @brief Change the last modification and access time of a file. * @brief Change the last modification and access time of a file.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param file The file which owner and group should be changed. * @param file The file which owner and group should be changed.
* *
* @param times A timeval structure which contains the desired acce ss * @param times A timeval structure which contains the desired acce ss
* and modification time. * and modification time.
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_utimes(SFTP_SESSION *sftp, const char *file, const struct timeval *times); LIBSSH_API int sftp_utimes(sftp_session sftp, const char *file, const struc t timeval *times);
/** /**
* @brief Create a symbolic link. * @brief Create a symbolic link.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param target Specifies the target of the symlink. * @param target Specifies the target of the symlink.
* *
* @param dest Specifies the path name of the symlink to be create d. * @param dest Specifies the path name of the symlink to be create d.
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
int sftp_symlink(SFTP_SESSION *sftp, const char *target, const char *dest); LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const ch ar *dest);
/** /**
* @brief Read the value of a symbolic link. * @brief Read the value of a symbolic link.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param path Specifies the path name of the symlink to be read. * @param path Specifies the path name of the symlink to be read.
* *
* @return The target of the link, NULL on error. * @return The target of the link, NULL on error.
*/ */
char *sftp_readlink(SFTP_SESSION *sftp, const char *path); LIBSSH_API char *sftp_readlink(sftp_session sftp, const char *path);
/**
* @brief Get information about a mounted file system.
*
* @param sftp The sftp session handle.
*
* @param path The pathname of any file within the mounted file sy
stem.
*
* @return A statvfs structure or NULL on error.
*/
LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path)
;
/**
* @brief Get information about a mounted file system.
*
* @param file An opened file.
*
* @return A statvfs structure or NULL on error.
*/
LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file);
/**
* @brief Free the memory of an allocated statvfs.
*
* @param statvfs_o The statvfs to free.
*/
LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o);
/** /**
* @brief Canonicalize a sftp path. * @brief Canonicalize a sftp path.
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @param path The path to be canonicalized. * @param path The path to be canonicalized.
* *
* @return The canonicalize path, NULL on error. * @return The canonicalize path, NULL on error.
*/ */
char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path); LIBSSH_API char *sftp_canonicalize_path(sftp_session sftp, const char *path );
/** /**
* @brief Get the version of the SFTP protocol supported by the server * @brief Get the version of the SFTP protocol supported by the server
* *
* @param sftp The sftp session handle. * @param sftp The sftp session handle.
* *
* @return The server version. * @return The server version.
*/ */
int sftp_server_version(SFTP_SESSION *sftp); LIBSSH_API int sftp_server_version(sftp_session sftp);
#ifdef WITH_SERVER #ifdef WITH_SERVER
/** /**
* @brief Create a new sftp server session. * @brief Create a new sftp server session.
* *
* @param session The ssh session to use. * @param session The ssh session to use.
* *
* @param chan The ssh channel to use. * @param chan The ssh channel to use.
* *
* @return A new sftp server session. * @return A new sftp server session.
*/ */
SFTP_SESSION *sftp_server_new(SSH_SESSION *session, CHANNEL *chan); LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel ch an);
/** /**
* @brief Intialize the sftp server. * @brief Intialize the sftp server.
* *
* @param sftp The sftp session to init. * @param sftp The sftp session to init.
* *
* @return 0 on success, < 0 on error. * @return 0 on success, < 0 on error.
*/ */
int sftp_server_init(SFTP_SESSION *sftp); LIBSSH_API int sftp_server_init(sftp_session sftp);
#endif /* WITH_SERVER */ #endif /* WITH_SERVER */
/* this is not a public interface */ /* this is not a public interface */
#define SFTP_HANDLES 256 #define SFTP_HANDLES 256
SFTP_PACKET *sftp_packet_read(SFTP_SESSION *sftp); sftp_packet sftp_packet_read(sftp_session sftp);
int sftp_packet_write(SFTP_SESSION *sftp,u8 type, BUFFER *payload); int sftp_packet_write(sftp_session sftp,uint8_t type, ssh_buffer payload);
void sftp_packet_free(SFTP_PACKET *packet); void sftp_packet_free(sftp_packet packet);
int buffer_add_attributes(BUFFER *buffer, SFTP_ATTRIBUTES *attr); int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr);
SFTP_ATTRIBUTES *sftp_parse_attr(SFTP_SESSION *session, BUFFER *buf,int exp sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,int ex
ectname); pectname);
/* sftpserver.c */ /* sftpserver.c */
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp); sftp_client_message sftp_get_client_message(sftp_session sftp);
void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg); void sftp_client_message_free(sftp_client_message msg);
int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name, int sftp_reply_name(sftp_client_message msg, const char *name,
SFTP_ATTRIBUTES *attr); sftp_attributes attr);
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, STRING *handle); int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info); ssh_string sftp_handle_alloc(sftp_session sftp, void *info);
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr); int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
void *sftp_handle(SFTP_SESSION *sftp, STRING *handle); void *sftp_handle(sftp_session sftp, ssh_string handle);
int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status, const char *mes int sftp_reply_status(sftp_client_message msg, uint32_t status, const char
sage); *message);
int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file, int sftp_reply_names_add(sftp_client_message msg, const char *file,
const char *longname, SFTP_ATTRIBUTES *attr); const char *longname, sftp_attributes attr);
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg); int sftp_reply_names(sftp_client_message msg);
int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len); int sftp_reply_data(sftp_client_message msg, const void *data, int len);
void sftp_handle_remove(SFTP_SESSION *sftp, void *handle); void sftp_handle_remove(sftp_session sftp, void *handle);
/* SFTP commands and constants */ /* SFTP commands and constants */
#define SSH_FXP_INIT 1 #define SSH_FXP_INIT 1
#define SSH_FXP_VERSION 2 #define SSH_FXP_VERSION 2
#define SSH_FXP_OPEN 3 #define SSH_FXP_OPEN 3
#define SSH_FXP_CLOSE 4 #define SSH_FXP_CLOSE 4
#define SSH_FXP_READ 5 #define SSH_FXP_READ 5
#define SSH_FXP_WRITE 6 #define SSH_FXP_WRITE 6
#define SSH_FXP_LSTAT 7 #define SSH_FXP_LSTAT 7
#define SSH_FXP_FSTAT 8 #define SSH_FXP_FSTAT 8
skipping to change at line 800 skipping to change at line 896
#define SFTP_READDIR SSH_FXP_READDIR #define SFTP_READDIR SSH_FXP_READDIR
#define SFTP_REMOVE SSH_FXP_REMOVE #define SFTP_REMOVE SSH_FXP_REMOVE
#define SFTP_MKDIR SSH_FXP_MKDIR #define SFTP_MKDIR SSH_FXP_MKDIR
#define SFTP_RMDIR SSH_FXP_RMDIR #define SFTP_RMDIR SSH_FXP_RMDIR
#define SFTP_REALPATH SSH_FXP_REALPATH #define SFTP_REALPATH SSH_FXP_REALPATH
#define SFTP_STAT SSH_FXP_STAT #define SFTP_STAT SSH_FXP_STAT
#define SFTP_RENAME SSH_FXP_RENAME #define SFTP_RENAME SSH_FXP_RENAME
#define SFTP_READLINK SSH_FXP_READLINK #define SFTP_READLINK SSH_FXP_READLINK
#define SFTP_SYMLINK SSH_FXP_SYMLINK #define SFTP_SYMLINK SSH_FXP_SYMLINK
/* openssh flags */
#define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
#define SSH_FXE_STATVFS_ST_NOSUID 0x2 /* no setuid */
#ifdef __cplusplus #ifdef __cplusplus
} ; } ;
#endif #endif
#endif /* SFTP_H */ #endif /* SFTP_H */
/** @} */ /** @} */
/* vim: set ts=2 sw=2 et cindent: */ /* vim: set ts=2 sw=2 et cindent: */
 End of changes. 72 change blocks. 
162 lines changed or deleted 267 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/