libssh
0.10.90
The SSH library
|
SFTP handling functions. More...
Data Structures | |
struct | sftp_statvfs_struct |
SFTP statvfs structure. More... | |
struct | sftp_limits_struct |
SFTP limits structure. More... | |
Macros | |
#define | LIBSFTP_VERSION 3 |
#define | SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */ |
#define | SSH_FXE_STATVFS_ST_NOSUID 0x2 /* no setuid */ |
Typedefs | |
typedef struct sftp_limits_struct * | sftp_limits_t |
typedef struct sftp_aio_struct * | sftp_aio |
Functions | |
LIBSSH_API sftp_session | sftp_new (ssh_session session) |
Creates a new sftp session. | |
LIBSSH_API sftp_session | sftp_new_channel (ssh_session session, ssh_channel channel) |
Start a new sftp session with an existing channel. | |
LIBSSH_API void | sftp_free (sftp_session sftp) |
Close and deallocate a sftp session. | |
LIBSSH_API int | sftp_init (sftp_session sftp) |
Initialize the sftp protocol with the server. | |
LIBSSH_API int | sftp_get_error (sftp_session sftp) |
Get the last sftp error. | |
LIBSSH_API unsigned int | sftp_extensions_get_count (sftp_session sftp) |
Get the count of extensions provided by the server. | |
LIBSSH_API const char * | sftp_extensions_get_name (sftp_session sftp, unsigned int indexn) |
Get the name of the extension provided by the server. | |
LIBSSH_API const char * | sftp_extensions_get_data (sftp_session sftp, unsigned int indexn) |
Get the data of the extension provided by the server. | |
LIBSSH_API int | sftp_extension_supported (sftp_session sftp, const char *name, const char *data) |
Check if the given extension is supported. | |
LIBSSH_API sftp_dir | sftp_opendir (sftp_session session, const char *path) |
Open a directory used to obtain directory entries. | |
LIBSSH_API sftp_attributes | sftp_readdir (sftp_session session, sftp_dir dir) |
Get a single file attributes structure of a directory. | |
LIBSSH_API int | sftp_dir_eof (sftp_dir dir) |
Tell if the directory has reached EOF (End Of File). | |
LIBSSH_API sftp_attributes | sftp_stat (sftp_session session, const char *path) |
Get information about a file or directory. | |
LIBSSH_API sftp_attributes | sftp_lstat (sftp_session session, const char *path) |
Get information about a file or directory. | |
LIBSSH_API sftp_attributes | sftp_fstat (sftp_file file) |
Get information about a file or directory from a file handle. | |
LIBSSH_API void | sftp_attributes_free (sftp_attributes file) |
Free a sftp attribute structure. | |
LIBSSH_API int | sftp_closedir (sftp_dir dir) |
Close a directory handle opened by sftp_opendir(). | |
LIBSSH_API int | sftp_close (sftp_file file) |
Close an open file handle. | |
LIBSSH_API sftp_file | sftp_open (sftp_session session, const char *file, int accesstype, mode_t mode) |
Open a file on the server. | |
LIBSSH_API void | sftp_file_set_nonblocking (sftp_file handle) |
Make the sftp communication for this file handle non blocking. | |
LIBSSH_API void | sftp_file_set_blocking (sftp_file handle) |
Make the sftp communication for this file handle blocking. | |
LIBSSH_API ssize_t | sftp_read (sftp_file file, void *buf, size_t count) |
Read from a file using an opened sftp file handle. | |
SSH_DEPRECATED LIBSSH_API int | sftp_async_read_begin (sftp_file file, uint32_t len) |
Start an asynchronous read from a file using an opened sftp file handle. | |
SSH_DEPRECATED LIBSSH_API int | sftp_async_read (sftp_file file, void *data, uint32_t len, uint32_t id) |
Wait for an asynchronous read to complete and save the data. | |
LIBSSH_API ssize_t | sftp_write (sftp_file file, const void *buf, size_t count) |
Write to a file using an opened sftp file handle. | |
LIBSSH_API void | sftp_aio_free (sftp_aio aio) |
Deallocate memory corresponding to a sftp aio handle. | |
LIBSSH_API ssize_t | sftp_aio_begin_read (sftp_file file, size_t len, sftp_aio *aio) |
Start an asynchronous read from a file using an opened sftp file handle. | |
LIBSSH_API ssize_t | sftp_aio_wait_read (sftp_aio *aio, void *buf, size_t buf_size) |
Wait for an asynchronous read to complete and store the read data in the supplied buffer. | |
LIBSSH_API ssize_t | sftp_aio_begin_write (sftp_file file, const void *buf, size_t len, sftp_aio *aio) |
Start an asynchronous write to a file using an opened sftp file handle. | |
LIBSSH_API ssize_t | sftp_aio_wait_write (sftp_aio *aio) |
Wait for an asynchronous write to complete. | |
LIBSSH_API int | sftp_seek (sftp_file file, uint32_t new_offset) |
Seek to a specific location in a file. | |
LIBSSH_API int | sftp_seek64 (sftp_file file, uint64_t new_offset) |
Seek to a specific location in a file. This is the 64bit version. | |
LIBSSH_API unsigned long | sftp_tell (sftp_file file) |
Report current byte position in file. | |
LIBSSH_API uint64_t | sftp_tell64 (sftp_file file) |
Report current byte position in file. | |
LIBSSH_API void | sftp_rewind (sftp_file file) |
Rewinds the position of the file pointer to the beginning of the file. | |
LIBSSH_API int | sftp_unlink (sftp_session sftp, const char *file) |
Unlink (delete) a file. | |
LIBSSH_API int | sftp_rmdir (sftp_session sftp, const char *directory) |
Remove a directory. | |
LIBSSH_API int | sftp_mkdir (sftp_session sftp, const char *directory, mode_t mode) |
Create a directory. | |
LIBSSH_API int | sftp_rename (sftp_session sftp, const char *original, const char *newname) |
Rename or move a file or directory. | |
LIBSSH_API int | sftp_setstat (sftp_session sftp, const char *file, sftp_attributes attr) |
Set file attributes on a file, directory or symbolic link. | |
LIBSSH_API int | sftp_chown (sftp_session sftp, const char *file, uid_t owner, gid_t group) |
Change the file owner and group. | |
LIBSSH_API int | sftp_chmod (sftp_session sftp, const char *file, mode_t mode) |
Change permissions of a file. | |
LIBSSH_API int | sftp_utimes (sftp_session sftp, const char *file, const struct timeval *times) |
Change the last modification and access time of a file. | |
LIBSSH_API int | sftp_symlink (sftp_session sftp, const char *target, const char *dest) |
Create a symbolic link. | |
LIBSSH_API char * | sftp_readlink (sftp_session sftp, const char *path) |
Read the value of a symbolic link. | |
LIBSSH_API int | sftp_hardlink (sftp_session sftp, const char *oldpath, const char *newpath) |
Create a hard link. | |
LIBSSH_API sftp_statvfs_t | sftp_statvfs (sftp_session sftp, const char *path) |
Get information about a mounted file system. | |
LIBSSH_API sftp_statvfs_t | sftp_fstatvfs (sftp_file file) |
Get information about a mounted file system. | |
LIBSSH_API void | sftp_statvfs_free (sftp_statvfs_t statvfs_o) |
Free the memory of an allocated statvfs. | |
LIBSSH_API int | sftp_fsync (sftp_file file) |
Synchronize a file's in-core state with storage device. | |
LIBSSH_API sftp_limits_t | sftp_limits (sftp_session sftp) |
Get information about the various limits the server might impose. | |
LIBSSH_API void | sftp_limits_free (sftp_limits_t limits) |
Free the memory of an allocated limits. | |
LIBSSH_API char * | sftp_canonicalize_path (sftp_session sftp, const char *path) |
Canonicalize a sftp path. | |
LIBSSH_API int | sftp_server_version (sftp_session sftp) |
Get the version of the SFTP protocol supported by the server. | |
LIBSSH_API char * | sftp_expand_path (sftp_session sftp, const char *path) |
Canonicalize path using expan.nosp@m.d-pa.nosp@m.th@op.nosp@m.enss.nosp@m.h.com extension. | |
LIBSSH_API sftp_session | sftp_server_new (ssh_session session, ssh_channel chan) |
Create a new sftp server session. | |
SSH_DEPRECATED LIBSSH_API int | sftp_server_init (sftp_session sftp) |
Initialize the sftp server. | |
LIBSSH_API void | sftp_server_free (sftp_session sftp) |
Close and deallocate a sftp server session. | |
LIBSSH_API sftp_client_message | sftp_get_client_message (sftp_session sftp) |
LIBSSH_API void | sftp_client_message_free (sftp_client_message msg) |
LIBSSH_API uint8_t | sftp_client_message_get_type (sftp_client_message msg) |
LIBSSH_API const char * | sftp_client_message_get_filename (sftp_client_message msg) |
LIBSSH_API void | sftp_client_message_set_filename (sftp_client_message msg, const char *newname) |
LIBSSH_API const char * | sftp_client_message_get_data (sftp_client_message msg) |
LIBSSH_API uint32_t | sftp_client_message_get_flags (sftp_client_message msg) |
LIBSSH_API const char * | sftp_client_message_get_submessage (sftp_client_message msg) |
LIBSSH_API int | sftp_send_client_message (sftp_session sftp, sftp_client_message msg) |
LIBSSH_API int | sftp_reply_name (sftp_client_message msg, const char *name, sftp_attributes attr) |
LIBSSH_API int | sftp_reply_handle (sftp_client_message msg, ssh_string handle) |
LIBSSH_API ssh_string | sftp_handle_alloc (sftp_session sftp, void *info) |
LIBSSH_API int | sftp_reply_attr (sftp_client_message msg, sftp_attributes attr) |
LIBSSH_API void * | sftp_handle (sftp_session sftp, ssh_string handle) |
LIBSSH_API int | sftp_reply_status (sftp_client_message msg, uint32_t status, const char *message) |
LIBSSH_API int | sftp_reply_names_add (sftp_client_message msg, const char *file, const char *longname, sftp_attributes attr) |
LIBSSH_API int | sftp_reply_names (sftp_client_message msg) |
LIBSSH_API int | sftp_reply_data (sftp_client_message msg, const void *data, int len) |
LIBSSH_API void | sftp_handle_remove (sftp_session sftp, void *handle) |
Server responses | |
Responses returned by the sftp server. | |
#define | SSH_FX_OK 0 |
#define | SSH_FX_EOF 1 |
#define | SSH_FX_NO_SUCH_FILE 2 |
#define | SSH_FX_PERMISSION_DENIED 3 |
#define | SSH_FX_FAILURE 4 |
#define | SSH_FX_BAD_MESSAGE 5 |
#define | SSH_FX_NO_CONNECTION 6 |
#define | SSH_FX_CONNECTION_LOST 7 |
#define | SSH_FX_OP_UNSUPPORTED 8 |
#define | SSH_FX_INVALID_HANDLE 9 |
#define | SSH_FX_NO_SUCH_PATH 10 |
#define | SSH_FX_FILE_ALREADY_EXISTS 11 |
#define | SSH_FX_WRITE_PROTECT 12 |
#define | SSH_FX_NO_MEDIA 13 |
SFTP handling functions.
SFTP commands are channeled by the ssh sftp subsystem. Every packet is 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 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 it can fetch it, while continuing to read for other messages (it is unspecified in which order messages may be sent back to the client
#define SSH_FX_BAD_MESSAGE 5 |
Garbage received from server
#define SSH_FX_CONNECTION_LOST 7 |
There was a connection, but we lost it
#define SSH_FX_EOF 1 |
End-of-file encountered
#define SSH_FX_FAILURE 4 |
Generic failure
#define SSH_FX_FILE_ALREADY_EXISTS 11 |
An attempt to create an already existing file or directory has been made
#define SSH_FX_INVALID_HANDLE 9 |
Invalid file handle
#define SSH_FX_NO_CONNECTION 6 |
No connection has been set up
#define SSH_FX_NO_MEDIA 13 |
No media in remote drive
#define SSH_FX_NO_SUCH_FILE 2 |
File doesn't exist
#define SSH_FX_NO_SUCH_PATH 10 |
No such file or directory path exists
#define SSH_FX_OK 0 |
No error
#define SSH_FX_OP_UNSUPPORTED 8 |
Operation not supported by the server
#define SSH_FX_PERMISSION_DENIED 3 |
Permission denied
#define SSH_FX_WRITE_PROTECT 12 |
We are trying to write on a write-protected filesystem
LIBSSH_API ssize_t sftp_aio_begin_read | ( | sftp_file | file, |
size_t | len, | ||
sftp_aio * | aio ) |
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 pattern of a synchronous read. To do so, you must call 2 functions :
sftp_aio_begin_read() and sftp_aio_wait_read().
These two functions do not close the open sftp file handle passed to sftp_aio_begin_read() irrespective of whether they fail or not.
It is the responsibility of the caller to ensure that the open sftp file handle passed to sftp_aio_begin_read() must not be closed before the corresponding call to sftp_aio_wait_read(). After sftp_aio_wait_read() returns, it is caller's decision whether to immediately close the file by calling sftp_close() or to keep it open and perform some more operations on it.
This function caps the length a user is allowed to read from an sftp file, the value of len parameter after capping is returned on success.
The value used for the cap is same as the value of the max_read_length field of the sftp_limits_t returned by sftp_limits().
file | The opened sftp file handle to be read from. |
len | Number of bytes to read. |
aio | Pointer to a location where the sftp aio handle (corresponding to the sent request) should be stored. |
LIBSSH_API ssize_t sftp_aio_begin_write | ( | sftp_file | file, |
const void * | buf, | ||
size_t | len, | ||
sftp_aio * | aio ) |
Start an asynchronous write to a file using an opened sftp file handle.
Its goal is to avoid the slowdowns related to the request/response pattern of a synchronous write. To do so, you must call 2 functions :
sftp_aio_begin_write() and sftp_aio_wait_write().
These two functions do not close the open sftp file handle passed to sftp_aio_begin_write() irrespective of whether they fail or not.
It is the responsibility of the caller to ensure that the open sftp file handle passed to sftp_aio_begin_write() must not be closed before the corresponding call to sftp_aio_wait_write(). After sftp_aio_wait_write() returns, it is caller's decision whether to immediately close the file by calling sftp_close() or to keep it open and perform some more operations on it.
This function caps the length a user is allowed to write to an sftp file, the value of len parameter after capping is returned on success.
The value used for the cap is same as the value of the max_write_length field of the sftp_limits_t returned by sftp_limits().
file | The opened sftp file handle to write to. |
buf | Pointer to the buffer containing data to write. |
len | Number of bytes to write. |
aio | Pointer to a location where the sftp aio handle (corresponding to the sent request) should be stored. |
LIBSSH_API void sftp_aio_free | ( | sftp_aio | aio | ) |
Deallocate memory corresponding to a sftp aio handle.
This function deallocates memory corresponding to the aio handle returned by the sftp_aio_begin_*() functions. Users can use this function to free memory corresponding to an aio handle for an outstanding async i/o request on encountering some error.
aio | sftp aio handle corresponding to which memory has to be deallocated. |
LIBSSH_API ssize_t sftp_aio_wait_read | ( | sftp_aio * | aio, |
void * | buf, | ||
size_t | buf_size ) |
Wait for an asynchronous read to complete and store the read data in the supplied buffer.
A pointer to an sftp aio handle should be passed while calling this function. Except when the return value is SSH_AGAIN, this function releases the memory corresponding to the supplied aio handle and assigns NULL to that aio handle using the passed pointer to that handle.
If the file is opened in non-blocking mode and the request hasn't been executed yet, this function returns SSH_AGAIN and must be called again using the same sftp aio handle.
aio | Pointer to the sftp aio handle returned by sftp_aio_begin_read(). |
buf | Pointer to the buffer in which read data will be stored. |
buf_size | Size of the buffer in bytes. It should be bigger or equal to the length parameter of the sftp_aio_begin_read() call. |
LIBSSH_API ssize_t sftp_aio_wait_write | ( | sftp_aio * | aio | ) |
Wait for an asynchronous write to complete.
A pointer to an sftp aio handle should be passed while calling this function. Except when the return value is SSH_AGAIN, this function releases the memory corresponding to the supplied aio handle and assigns NULL to that aio handle using the passed pointer to that handle.
If the file is opened in non-blocking mode and the request hasn't been executed yet, this function returns SSH_AGAIN and must be called again using the same sftp aio handle.
aio | Pointer to the sftp aio handle returned by sftp_aio_begin_write(). |
SSH_DEPRECATED LIBSSH_API int sftp_async_read | ( | sftp_file | file, |
void * | data, | ||
uint32_t | len, | ||
uint32_t | id ) |
Wait for an asynchronous read to complete and save the data.
file | The opened sftp file handle to be read from. |
data | Pointer to buffer to receive read data. |
len | Size of the buffer in bytes. It should be bigger or equal to the length parameter of the sftp_async_read_begin() call. |
id | The identifier returned by the sftp_async_read_begin() function. |
SSH_DEPRECATED LIBSSH_API int sftp_async_read_begin | ( | sftp_file | file, |
uint32_t | len ) |
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 pattern of a synchronous read. To do so, you must call 2 functions:
sftp_async_read_begin() and sftp_async_read().
The first step is to call sftp_async_read_begin(). This function returns a request identifier. The second step is to call sftp_async_read() using the returned identifier.
file | The opened sftp file handle to be read from. |
len | Size to read in bytes. |
LIBSSH_API void sftp_attributes_free | ( | sftp_attributes | file | ) |
Free a sftp attribute structure.
file | The sftp attribute structure to free. |
LIBSSH_API char * sftp_canonicalize_path | ( | sftp_session | sftp, |
const char * | path ) |
Canonicalize a sftp path.
sftp | The sftp session handle. |
path | The path to be canonicalized. |
LIBSSH_API int sftp_chmod | ( | sftp_session | sftp, |
const char * | file, | ||
mode_t | mode ) |
Change permissions of a file.
sftp | The sftp session handle. |
file | The file which owner and group should be changed. |
mode | Specifies the permissions to use. It is modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask) |
LIBSSH_API int sftp_chown | ( | sftp_session | sftp, |
const char * | file, | ||
uid_t | owner, | ||
gid_t | group ) |
Change the file owner and group.
sftp | The sftp session handle. |
file | The file which owner and group should be changed. |
owner | The new owner which should be set. |
group | The new group which should be set. |
LIBSSH_API int sftp_close | ( | sftp_file | file | ) |
Close an open file handle.
file | The open sftp file handle to close. |
LIBSSH_API int sftp_closedir | ( | sftp_dir | dir | ) |
Close a directory handle opened by sftp_opendir().
dir | The sftp directory handle to close. |
LIBSSH_API int sftp_dir_eof | ( | sftp_dir | dir | ) |
Tell if the directory has reached EOF (End Of File).
dir | The sftp directory handle. |
LIBSSH_API char * sftp_expand_path | ( | sftp_session | sftp, |
const char * | path ) |
Canonicalize path using expan.nosp@m.d-pa.nosp@m.th@op.nosp@m.enss.nosp@m.h.com extension.
sftp | The sftp session handle. |
path | The path to be canonicalized. |
LIBSSH_API int sftp_extension_supported | ( | sftp_session | sftp, |
const char * | name, | ||
const char * | data ) |
Check if the given extension is supported.
sftp | The sftp session to use. |
name | The name of the extension. |
data | The data of the extension. |
Example:
LIBSSH_API unsigned int sftp_extensions_get_count | ( | sftp_session | sftp | ) |
Get the count of extensions provided by the server.
sftp | The sftp session to use. |
LIBSSH_API const char * sftp_extensions_get_data | ( | sftp_session | sftp, |
unsigned int | indexn ) |
Get the data of the extension provided by the server.
This is normally the version number of the extension.
sftp | The sftp session to use. |
indexn | The index number of the extension data you want. |
LIBSSH_API const char * sftp_extensions_get_name | ( | sftp_session | sftp, |
unsigned int | indexn ) |
Get the name of the extension provided by the server.
sftp | The sftp session to use. |
indexn | The index number of the extension name you want. |
LIBSSH_API void sftp_file_set_blocking | ( | sftp_file | handle | ) |
Make the sftp communication for this file handle blocking.
[in] | handle | The file handle to set blocking. |
LIBSSH_API void sftp_file_set_nonblocking | ( | sftp_file | handle | ) |
Make the sftp communication for this file handle non blocking.
[in] | handle | The file handle to set non blocking. |
LIBSSH_API void sftp_free | ( | sftp_session | sftp | ) |
Close and deallocate a sftp session.
sftp | The sftp session handle to free. |
LIBSSH_API sftp_attributes sftp_fstat | ( | sftp_file | file | ) |
Get information about a file or directory from a file handle.
file | The sftp file handle to get the stat information. |
LIBSSH_API sftp_statvfs_t sftp_fstatvfs | ( | sftp_file | file | ) |
Get information about a mounted file system.
file | An opened file. |
LIBSSH_API int sftp_fsync | ( | sftp_file | file | ) |
Synchronize a file's in-core state with storage device.
This calls the "fsync@openssh.com" extension. You should check if the extensions is supported using:
file | The opened sftp file handle to sync |
LIBSSH_API int sftp_get_error | ( | sftp_session | sftp | ) |
Get the last sftp error.
Use this function to get the latest error set by a posix like sftp function.
sftp | The sftp session where the error is saved. |
LIBSSH_API int sftp_hardlink | ( | sftp_session | sftp, |
const char * | oldpath, | ||
const char * | newpath ) |
Create a hard link.
sftp | The sftp session handle. |
oldpath | Specifies the pathname of the file for which the new hardlink is to be created. |
newpath | Specifies the pathname of the hardlink to be created. |
LIBSSH_API int sftp_init | ( | sftp_session | sftp | ) |
Initialize the sftp protocol with the server.
This function involves the SFTP protocol initialization (as described in the SFTP specification), including the version and extensions negotiation.
sftp | The sftp session to initialize. |
LIBSSH_API sftp_limits_t sftp_limits | ( | sftp_session | sftp | ) |
Get information about the various limits the server might impose.
sftp | The sftp session handle. |
LIBSSH_API void sftp_limits_free | ( | sftp_limits_t | limits | ) |
Free the memory of an allocated limits.
limits | The limits to free. |
LIBSSH_API sftp_attributes sftp_lstat | ( | sftp_session | session, |
const char * | path ) |
Get information about a file or directory.
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.
session | The sftp session handle. |
path | The path to the file or directory to obtain the information. |
LIBSSH_API int sftp_mkdir | ( | sftp_session | sftp, |
const char * | directory, | ||
mode_t | mode ) |
Create a directory.
sftp | The sftp session handle. |
directory | The directory to create. |
mode | Specifies the permissions to use. It is modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask) |
LIBSSH_API sftp_session sftp_new | ( | ssh_session | session | ) |
Creates a new sftp session.
This function creates a new sftp session and allocates a new sftp channel with the server inside of the provided ssh session. This function call is usually followed by the sftp_init(), which initializes SFTP protocol itself.
session | The ssh session to use. |
LIBSSH_API sftp_session sftp_new_channel | ( | ssh_session | session, |
ssh_channel | channel ) |
Start a new sftp session with an existing channel.
session | The ssh session to use. |
channel | An open session channel with subsystem already allocated |
LIBSSH_API sftp_file sftp_open | ( | sftp_session | session, |
const char * | file, | ||
int | accesstype, | ||
mode_t | mode ) |
Open a file on the server.
session | The sftp session handle. |
file | The file to be opened. |
accesstype | Is one of O_RDONLY, O_WRONLY or O_RDWR which request opening the file read-only,write-only or read/write. Acesss may also be bitwise-or'd with one or more of the following: O_CREAT - If the file does not exist it will be created. O_EXCL - When used with O_CREAT, if the file already exists it is an error and the open will fail. O_TRUNC - If the file already exists it will be truncated. |
mode | Mode specifies the permissions to use if a new file is created. It is modified by the process's umask in the usual way: The permissions of the created file are (mode & ~umask) |
LIBSSH_API sftp_dir sftp_opendir | ( | sftp_session | session, |
const char * | path ) |
Open a directory used to obtain directory entries.
session | The sftp session handle to open the directory. |
path | The path of the directory to open. |
LIBSSH_API ssize_t sftp_read | ( | sftp_file | file, |
void * | buf, | ||
size_t | count ) |
Read from a file using an opened sftp file handle.
file | The opened sftp file handle to be read from. |
buf | Pointer to buffer to receive read data. |
count | Size of the buffer in bytes. |
LIBSSH_API sftp_attributes sftp_readdir | ( | sftp_session | session, |
sftp_dir | dir ) |
Get a single file attributes structure of a directory.
session | The sftp session handle to read the directory entry. |
dir | The opened sftp directory handle to read from. |
LIBSSH_API char * sftp_readlink | ( | sftp_session | sftp, |
const char * | path ) |
Read the value of a symbolic link.
sftp | The sftp session handle. |
path | Specifies the path name of the symlink to be read. |
LIBSSH_API int sftp_rename | ( | sftp_session | sftp, |
const char * | original, | ||
const char * | newname ) |
Rename or move a file or directory.
sftp | The sftp session handle. |
original | The original url (source url) of file or directory to be moved. |
newname | The new url (destination url) of the file or directory after the move. |
LIBSSH_API void sftp_rewind | ( | sftp_file | file | ) |
Rewinds the position of the file pointer to the beginning of the file.
file | Open sftp file handle. |
LIBSSH_API int sftp_rmdir | ( | sftp_session | sftp, |
const char * | directory ) |
Remove a directory.
sftp | The sftp session handle. |
directory | The directory to remove. |
LIBSSH_API int sftp_seek | ( | sftp_file | file, |
uint32_t | new_offset ) |
Seek to a specific location in a file.
file | Open sftp file handle to seek in. |
new_offset | Offset in bytes to seek. |
LIBSSH_API int sftp_seek64 | ( | sftp_file | file, |
uint64_t | new_offset ) |
Seek to a specific location in a file. This is the 64bit version.
file | Open sftp file handle to seek in. |
new_offset | Offset in bytes to seek. |
LIBSSH_API void sftp_server_free | ( | sftp_session | sftp | ) |
Close and deallocate a sftp server session.
sftp | The sftp session handle to free. |
SSH_DEPRECATED LIBSSH_API int sftp_server_init | ( | sftp_session | sftp | ) |
Initialize the sftp server.
sftp | The sftp session to init. |
LIBSSH_API sftp_session sftp_server_new | ( | ssh_session | session, |
ssh_channel | chan ) |
Create a new sftp server session.
session | The ssh session to use. |
chan | The ssh channel to use. |
LIBSSH_API int sftp_server_version | ( | sftp_session | sftp | ) |
Get the version of the SFTP protocol supported by the server.
sftp | The sftp session handle. |
LIBSSH_API int sftp_setstat | ( | sftp_session | sftp, |
const char * | file, | ||
sftp_attributes | attr ) |
Set file attributes on a file, directory or symbolic link.
Note, that this function can only set time values using 32 bit values due to the restrictions in the SFTP protocol version 3 implemented by libssh. The support for 64 bit time values was introduced in SFTP version 5, which is not implemented by libssh nor any major SFTP servers.
sftp | The sftp session handle. |
file | The file which attributes should be changed. |
attr | The file attributes structure with the attributes set which should be changed. |
LIBSSH_API sftp_attributes sftp_stat | ( | sftp_session | session, |
const char * | path ) |
Get information about a file or directory.
session | The sftp session handle. |
path | The path to the file or directory to obtain the information. |
LIBSSH_API sftp_statvfs_t sftp_statvfs | ( | sftp_session | sftp, |
const char * | path ) |
Get information about a mounted file system.
sftp | The sftp session handle. |
path | The pathname of any file within the mounted file system. |
LIBSSH_API void sftp_statvfs_free | ( | sftp_statvfs_t | statvfs_o | ) |
Free the memory of an allocated statvfs.
statvfs_o | The statvfs to free. |
LIBSSH_API int sftp_symlink | ( | sftp_session | sftp, |
const char * | target, | ||
const char * | dest ) |
Create a symbolic link.
sftp | The sftp session handle. |
target | Specifies the target of the symlink. |
dest | Specifies the path name of the symlink to be created. |
LIBSSH_API unsigned long sftp_tell | ( | sftp_file | file | ) |
Report current byte position in file.
file | Open sftp file handle. |
LIBSSH_API uint64_t sftp_tell64 | ( | sftp_file | file | ) |
Report current byte position in file.
file | Open sftp file handle. |
LIBSSH_API int sftp_unlink | ( | sftp_session | sftp, |
const char * | file ) |
Unlink (delete) a file.
sftp | The sftp session handle. |
file | The file to unlink/delete. |
LIBSSH_API int sftp_utimes | ( | sftp_session | sftp, |
const char * | file, | ||
const struct timeval * | times ) |
Change the last modification and access time of a file.
sftp | The sftp session handle. |
file | The file which owner and group should be changed. |
times | A timeval structure which contains the desired access and modification time. |
LIBSSH_API ssize_t sftp_write | ( | sftp_file | file, |
const void * | buf, | ||
size_t | count ) |
Write to a file using an opened sftp file handle.
The maximum size of the SFTP packet payload is 32768 bytes so the count parameter is capped at this value. This is low-level function so it does not try to send more than this amount of data.
file | Open sftp file handle to write to. |
buf | Pointer to buffer to write data. |
count | Size of buffer in bytes. |