50 typedef uint32_t uid_t;
53 typedef uint32_t gid_t;
57# ifndef _SSIZE_T_DEFINED
60 typedef _W64 SSIZE_T ssize_t;
61# define _SSIZE_T_DEFINED
67#define LIBSFTP_VERSION 3
69typedef struct sftp_attributes_struct* sftp_attributes;
70typedef struct sftp_client_message_struct* sftp_client_message;
71typedef struct sftp_dir_struct* sftp_dir;
72typedef struct sftp_ext_struct *sftp_ext;
73typedef struct sftp_file_struct* sftp_file;
74typedef struct sftp_message_struct* sftp_message;
75typedef struct sftp_packet_struct* sftp_packet;
76typedef struct sftp_request_queue_struct* sftp_request_queue;
77typedef struct sftp_session_struct* sftp_session;
78typedef struct sftp_status_message_struct* sftp_status_message;
84struct sftp_session_struct {
90 sftp_request_queue queue;
95 sftp_packet read_packet;
99struct sftp_packet_struct {
106struct sftp_file_struct {
115struct sftp_dir_struct {
124struct sftp_message_struct {
132struct sftp_client_message_struct {
138 sftp_attributes attr;
145 ssh_buffer complete_message;
150struct sftp_request_queue_struct {
151 sftp_request_queue next;
152 sftp_message message;
156struct sftp_status_message_struct {
159 ssh_string error_unused;
160 ssh_string lang_unused;
165struct sftp_attributes_struct {
175 uint32_t permissions;
178 uint32_t atime_nseconds;
180 uint32_t createtime_nseconds;
183 uint32_t mtime_nseconds;
185 uint32_t extended_count;
186 ssh_string extended_type;
187 ssh_string extended_data;
211 uint64_t max_packet_length;
250LIBSSH_API sftp_session
sftp_new(ssh_session session);
265LIBSSH_API sftp_session
sftp_new_channel(ssh_session session, ssh_channel channel);
273LIBSSH_API
void sftp_free(sftp_session sftp);
287LIBSSH_API
int sftp_init(sftp_session sftp);
369LIBSSH_API sftp_dir
sftp_opendir(sftp_session session,
const char *path);
384LIBSSH_API sftp_attributes
sftp_readdir(sftp_session session, sftp_dir dir);
409LIBSSH_API sftp_attributes
sftp_stat(sftp_session session,
const char *path);
426LIBSSH_API sftp_attributes
sftp_lstat(sftp_session session,
const char *path);
438LIBSSH_API sftp_attributes
sftp_fstat(sftp_file file);
495LIBSSH_API sftp_file
sftp_open(sftp_session session,
const char *file,
int accesstype,
531LIBSSH_API ssize_t
sftp_read(sftp_file file,
void *buf,
size_t count);
616LIBSSH_API ssize_t
sftp_write(sftp_file file,
const void *buf,
size_t count);
635#define SFTP_AIO_FREE(x) \
636 do { if(x != NULL) {sftp_aio_free(x); x = NULL;} } while(0)
850LIBSSH_API
int sftp_seek(sftp_file file, uint32_t new_offset);
862LIBSSH_API
int sftp_seek64(sftp_file file, uint64_t new_offset);
873LIBSSH_API
unsigned long sftp_tell(sftp_file file);
904LIBSSH_API
int sftp_unlink(sftp_session sftp,
const char *file);
917LIBSSH_API
int sftp_rmdir(sftp_session sftp,
const char *directory);
934LIBSSH_API
int sftp_mkdir(sftp_session sftp,
const char *directory, mode_t mode);
951LIBSSH_API
int sftp_rename(sftp_session sftp,
const char *original,
const char *newname);
972LIBSSH_API
int sftp_setstat(sftp_session sftp,
const char *file, sftp_attributes attr);
995sftp_lsetstat(sftp_session sftp,
const char *file, sftp_attributes attr);
1012LIBSSH_API
int sftp_chown(sftp_session sftp,
const char *file, uid_t owner, gid_t group);
1029LIBSSH_API
int sftp_chmod(sftp_session sftp,
const char *file, mode_t mode);
1045LIBSSH_API
int sftp_utimes(sftp_session sftp,
const char *file,
const struct timeval *times);
1060LIBSSH_API
int sftp_symlink(sftp_session sftp,
const char *target,
const char *dest);
1075LIBSSH_API
char *
sftp_readlink(sftp_session sftp,
const char *path);
1091LIBSSH_API
int sftp_hardlink(sftp_session sftp,
const char *oldpath,
const char *newpath);
1104LIBSSH_API sftp_statvfs_t
sftp_statvfs(sftp_session sftp,
const char *path);
1149LIBSSH_API sftp_limits_t
sftp_limits(sftp_session sftp);
1263 sftp_name_id_map users_map,
1264 sftp_name_id_map groups_map);
1276LIBSSH_API sftp_session
sftp_server_new(ssh_session session, ssh_channel chan);
1297LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp);
1298LIBSSH_API
void sftp_client_message_free(sftp_client_message msg);
1299LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg);
1300LIBSSH_API
const char *sftp_client_message_get_filename(sftp_client_message msg);
1301LIBSSH_API
void sftp_client_message_set_filename(sftp_client_message msg,
const char *newname);
1302LIBSSH_API
const char *sftp_client_message_get_data(sftp_client_message msg);
1303LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg);
1304LIBSSH_API
const char *sftp_client_message_get_submessage(sftp_client_message msg);
1305LIBSSH_API
int sftp_send_client_message(sftp_session sftp, sftp_client_message msg);
1306LIBSSH_API
int sftp_reply_name(sftp_client_message msg,
const char *name,
1307 sftp_attributes attr);
1308LIBSSH_API
int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
1309LIBSSH_API ssh_string sftp_handle_alloc(sftp_session sftp,
void *info);
1310LIBSSH_API
int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
1311LIBSSH_API
void *
sftp_handle(sftp_session sftp, ssh_string handle);
1312LIBSSH_API
int sftp_reply_status(sftp_client_message msg, uint32_t status,
const char *message);
1313LIBSSH_API
int sftp_reply_names_add(sftp_client_message msg,
const char *file,
1314 const char *longname, sftp_attributes attr);
1315LIBSSH_API
int sftp_reply_names(sftp_client_message msg);
1316LIBSSH_API
int sftp_reply_data(sftp_client_message msg,
const void *data,
int len);
1317LIBSSH_API
void sftp_handle_remove(sftp_session sftp,
void *handle);
1320#define SSH_FXP_INIT 1
1321#define SSH_FXP_VERSION 2
1322#define SSH_FXP_OPEN 3
1323#define SSH_FXP_CLOSE 4
1324#define SSH_FXP_READ 5
1325#define SSH_FXP_WRITE 6
1326#define SSH_FXP_LSTAT 7
1327#define SSH_FXP_FSTAT 8
1328#define SSH_FXP_SETSTAT 9
1329#define SSH_FXP_FSETSTAT 10
1330#define SSH_FXP_OPENDIR 11
1331#define SSH_FXP_READDIR 12
1332#define SSH_FXP_REMOVE 13
1333#define SSH_FXP_MKDIR 14
1334#define SSH_FXP_RMDIR 15
1335#define SSH_FXP_REALPATH 16
1336#define SSH_FXP_STAT 17
1337#define SSH_FXP_RENAME 18
1338#define SSH_FXP_READLINK 19
1339#define SSH_FXP_SYMLINK 20
1341#define SSH_FXP_STATUS 101
1342#define SSH_FXP_HANDLE 102
1343#define SSH_FXP_DATA 103
1344#define SSH_FXP_NAME 104
1345#define SSH_FXP_ATTRS 105
1347#define SSH_FXP_EXTENDED 200
1348#define SSH_FXP_EXTENDED_REPLY 201
1355#define SSH_FILEXFER_ATTR_SIZE 0x00000001
1356#define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
1357#define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
1358#define SSH_FILEXFER_ATTR_ACMODTIME 0x00000008
1359#define SSH_FILEXFER_ATTR_CREATETIME 0x00000010
1360#define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020
1361#define SSH_FILEXFER_ATTR_ACL 0x00000040
1362#define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080
1363#define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
1364#define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
1365#define SSH_FILEXFER_ATTR_UIDGID 0x00000002
1368#define SSH_FILEXFER_TYPE_REGULAR 1
1369#define SSH_FILEXFER_TYPE_DIRECTORY 2
1370#define SSH_FILEXFER_TYPE_SYMLINK 3
1371#define SSH_FILEXFER_TYPE_SPECIAL 4
1372#define SSH_FILEXFER_TYPE_UNKNOWN 5
1386#define SSH_FX_NO_SUCH_FILE 2
1388#define SSH_FX_PERMISSION_DENIED 3
1390#define SSH_FX_FAILURE 4
1392#define SSH_FX_BAD_MESSAGE 5
1394#define SSH_FX_NO_CONNECTION 6
1396#define SSH_FX_CONNECTION_LOST 7
1398#define SSH_FX_OP_UNSUPPORTED 8
1400#define SSH_FX_INVALID_HANDLE 9
1402#define SSH_FX_NO_SUCH_PATH 10
1404#define SSH_FX_FILE_ALREADY_EXISTS 11
1406#define SSH_FX_WRITE_PROTECT 12
1408#define SSH_FX_NO_MEDIA 13
1413#define SSH_FXF_READ 0x01
1414#define SSH_FXF_WRITE 0x02
1415#define SSH_FXF_APPEND 0x04
1416#define SSH_FXF_CREAT 0x08
1417#define SSH_FXF_TRUNC 0x10
1418#define SSH_FXF_EXCL 0x20
1419#define SSH_FXF_TEXT 0x40
1422#define SSH_S_IFMT 00170000
1423#define SSH_S_IFSOCK 0140000
1424#define SSH_S_IFLNK 0120000
1425#define SSH_S_IFREG 0100000
1426#define SSH_S_IFBLK 0060000
1427#define SSH_S_IFDIR 0040000
1428#define SSH_S_IFCHR 0020000
1429#define SSH_S_IFIFO 0010000
1432#define SSH_FXF_RENAME_OVERWRITE 0x00000001
1433#define SSH_FXF_RENAME_ATOMIC 0x00000002
1434#define SSH_FXF_RENAME_NATIVE 0x00000004
1436#define SFTP_OPEN SSH_FXP_OPEN
1437#define SFTP_CLOSE SSH_FXP_CLOSE
1438#define SFTP_READ SSH_FXP_READ
1439#define SFTP_WRITE SSH_FXP_WRITE
1440#define SFTP_LSTAT SSH_FXP_LSTAT
1441#define SFTP_FSTAT SSH_FXP_FSTAT
1442#define SFTP_SETSTAT SSH_FXP_SETSTAT
1443#define SFTP_FSETSTAT SSH_FXP_FSETSTAT
1444#define SFTP_OPENDIR SSH_FXP_OPENDIR
1445#define SFTP_READDIR SSH_FXP_READDIR
1446#define SFTP_REMOVE SSH_FXP_REMOVE
1447#define SFTP_MKDIR SSH_FXP_MKDIR
1448#define SFTP_RMDIR SSH_FXP_RMDIR
1449#define SFTP_REALPATH SSH_FXP_REALPATH
1450#define SFTP_STAT SSH_FXP_STAT
1451#define SFTP_RENAME SSH_FXP_RENAME
1452#define SFTP_READLINK SSH_FXP_READLINK
1453#define SFTP_SYMLINK SSH_FXP_SYMLINK
1454#define SFTP_EXTENDED SSH_FXP_EXTENDED
1457#define SSH_FXE_STATVFS_ST_RDONLY 0x1
1458#define SSH_FXE_STATVFS_ST_NOSUID 0x2
LIBSSH_API sftp_attributes sftp_fstat(sftp_file file)
Get information about a file or directory from a file handle.
Definition sftp.c:3026
LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle)
Make the sftp communication for this file handle non blocking.
Definition sftp.c:1142
LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode)
Create a directory.
Definition sftp.c:1692
LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname)
Rename or move a file or directory.
Definition sftp.c:1792
LIBSSH_API const char * sftp_extensions_get_name(sftp_session sftp, unsigned int indexn)
Get the name of the extension provided by the server.
Definition sftp.c:594
LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o)
Free the memory of an allocated statvfs.
Definition sftp.c:2668
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.
Definition sftp.c:2098
LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir)
Get a single file attributes structure of a directory.
Definition sftp.c:780
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.
Definition sftp.c:1523
LIBSSH_API int sftp_closedir(sftp_dir dir)
Close a directory handle opened by sftp_opendir().
Definition sftp.c:1001
LIBSSH_API int sftp_close(sftp_file file)
Close an open file handle.
Definition sftp.c:982
LIBSSH_API sftp_name_id_map sftp_name_id_map_new(uint32_t count)
Create a new sftp_name_id_map struct.
Definition sftp.c:3310
LIBSSH_API char * sftp_expand_path(sftp_session sftp, const char *path)
Canonicalize path using expand-path@openssh.com extension.
Definition sftp.c:3095
SSH_DEPRECATED LIBSSH_API int sftp_server_init(sftp_session sftp)
Initialize the sftp server.
Definition sftp.c:277
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.
Definition sftp_aio.c:139
LIBSSH_API void sftp_server_free(sftp_session sftp)
Close and deallocate a sftp server session.
Definition sftp.c:310
LIBSSH_API ssize_t sftp_aio_wait_write(sftp_aio *aio)
Wait for an asynchronous write to complete.
Definition sftp_aio.c:404
LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp)
Get the count of extensions provided by the server.
Definition sftp.c:586
LIBSSH_API void sftp_aio_free(sftp_aio aio)
Deallocate memory corresponding to a sftp aio handle.
Definition sftp_aio.c:48
LIBSSH_API int sftp_get_error(sftp_session sftp)
Get the last sftp error.
Definition sftp.c:427
LIBSSH_API unsigned long sftp_tell(sftp_file file)
Report current byte position in file.
Definition sftp.c:1536
LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file)
Unlink (delete) a file.
Definition sftp.c:1551
LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path)
Get information about a file or directory.
Definition sftp.c:3022
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.
Definition sftp.c:1323
LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file)
Get information about a mounted file system.
Definition sftp.c:2594
LIBSSH_API void sftp_free(sftp_session sftp)
Close and deallocate a sftp session.
Definition sftp.c:338
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.
Definition sftp_aio.c:53
LIBSSH_API sftp_limits_t sftp_limits(sftp_session sftp)
Get information about the various limits the server might impose.
Definition sftp.c:2820
LIBSSH_API int sftp_lsetstat(sftp_session sftp, const char *file, sftp_attributes attr)
This request is like setstat (excluding mode and size) but sets file attributes on symlinks themselve...
Definition sftp.c:1988
LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset)
Seek to a specific location in a file.
Definition sftp.c:1510
LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel chan)
Create a new sftp server session.
Definition sftp.c:239
LIBSSH_API void sftp_attributes_free(sftp_attributes file)
Free a sftp attribute structure.
Definition sftp.c:895
LIBSSH_API void sftp_limits_free(sftp_limits_t limits)
Free the memory of an allocated limits.
Definition sftp.c:2847
LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path)
Get information about a file or directory.
Definition sftp.c:3018
LIBSSH_API const char * sftp_extensions_get_data(sftp_session sftp, unsigned int indexn)
Get the data of the extension provided by the server.
Definition sftp.c:610
LIBSSH_API uint64_t sftp_tell64(sftp_file file)
Report current byte position in file.
Definition sftp.c:1540
LIBSSH_API char * sftp_home_directory(sftp_session sftp, const char *username)
Get the specified user's home directory.
Definition sftp.c:3187
LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group)
Change the file owner and group.
Definition sftp.c:2075
LIBSSH_API char * sftp_readlink(sftp_session sftp, const char *path)
Read the value of a symbolic link.
Definition sftp.c:2208
LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name, const char *data)
Check if the given extension is supported.
Definition sftp.c:627
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.
Definition sftp.c:1287
LIBSSH_API sftp_session sftp_new_channel(ssh_session session, ssh_channel channel)
Start a new sftp session with an existing channel.
Definition sftp.c:186
LIBSSH_API sftp_file sftp_open(sftp_session session, const char *file, int accesstype, mode_t mode)
Open a file on the server.
Definition sftp.c:1017
LIBSSH_API void sftp_file_set_blocking(sftp_file handle)
Make the sftp communication for this file handle blocking.
Definition sftp.c:1146
LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory)
Remove a directory.
Definition sftp.c:1624
LIBSSH_API void sftp_rewind(sftp_file file)
Rewinds the position of the file pointer to the beginning of the file.
Definition sftp.c:1545
LIBSSH_API int sftp_dir_eof(sftp_dir dir)
Tell if the directory has reached EOF (End Of File).
Definition sftp.c:890
LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path)
Open a directory used to obtain directory entries.
Definition sftp.c:685
LIBSSH_API int sftp_init(sftp_session sftp)
Initialize the sftp protocol with the server.
Definition sftp.c:439
LIBSSH_API ssize_t sftp_read(sftp_file file, void *buf, size_t count)
Read from a file using an opened sftp file handle.
Definition sftp.c:1153
LIBSSH_API int sftp_server_version(sftp_session sftp)
Get the version of the SFTP protocol supported by the server.
Definition sftp.c:775
LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr)
Set file attributes on a file, directory or symbolic link.
Definition sftp.c:1903
LIBSSH_API int sftp_get_users_groups_by_id(sftp_session sftp, sftp_name_id_map users_map, sftp_name_id_map groups_map)
Retrieves usernames and group names based on provided user and group IDs.
Definition sftp.c:3404
LIBSSH_API char * sftp_canonicalize_path(sftp_session sftp, const char *path)
Canonicalize a sftp path.
Definition sftp.c:2857
LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest)
Create a symbolic link.
Definition sftp.c:2115
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.
Definition sftp_aio.c:306
LIBSSH_API sftp_session sftp_new(ssh_session session)
Creates a new sftp session.
Definition sftp.c:103
LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode)
Change permissions of a file.
Definition sftp.c:2088
LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path)
Get information about a mounted file system.
Definition sftp.c:2419
LIBSSH_API int sftp_fsync(sftp_file file)
Synchronize a file's in-core state with storage device.
Definition sftp.c:2500
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.
Definition sftp.c:1405
LIBSSH_API void sftp_name_id_map_free(sftp_name_id_map map)
Free the memory of an allocated sftp_name_id_map struct.
Definition sftp.c:3337
LIBSSH_API int sftp_hardlink(sftp_session sftp, const char *oldpath, const char *newpath)
Create a hard link.
Definition sftp.c:2299
Definition sftpserver.c:816
SFTP limits structure.
Definition sftp.h:210
uint64_t max_write_length
Definition sftp.h:213
uint64_t max_open_handles
Definition sftp.h:214
uint64_t max_read_length
Definition sftp.h:212
SFTP names map structure to store the mapping between ids and names.
Definition sftp.h:222
uint32_t * ids
Array of ids, ids[i] mapped to names[i].
Definition sftp.h:227
char ** names
Array of names, names[i] mapped to ids[i].
Definition sftp.h:230
uint32_t count
Count of name-id pairs in the map.
Definition sftp.h:224
SFTP statvfs structure.
Definition sftp.h:193
uint64_t f_blocks
Definition sftp.h:196
uint64_t f_ffree
Definition sftp.h:200
uint64_t f_files
Definition sftp.h:199
uint64_t f_bavail
Definition sftp.h:198
uint64_t f_namemax
Definition sftp.h:204
uint64_t f_bfree
Definition sftp.h:197
uint64_t f_favail
Definition sftp.h:201
uint64_t f_flag
Definition sftp.h:203
uint64_t f_frsize
Definition sftp.h:195
uint64_t f_fsid
Definition sftp.h:202