libssh 0.12.1 The SSH library

Loading...
Searching...
No Matches
sftp.h
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2003-2008 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
36
37#ifndef SFTP_H
38#define SFTP_H
39
40#include <sys/types.h>
41
42#include "libssh.h"
43
44#ifdef __cplusplus
45 extern "C" {
46#endif
47
48#ifdef _WIN32
49#ifndef uid_t
50 typedef uint32_t uid_t;
51#endif /* uid_t */
52#ifndef gid_t
53 typedef uint32_t gid_t;
54#endif /* gid_t */
55#ifdef _MSC_VER
56
57# ifndef _SSIZE_T_DEFINED
58# undef ssize_t
59# include <BaseTsd.h>
60 typedef _W64 SSIZE_T ssize_t;
61# define _SSIZE_T_DEFINED
62# endif /* _SSIZE_T_DEFINED */
63
64#endif /* _MSC_VER */
65#endif /* _WIN32 */
66
67#define LIBSFTP_VERSION 3
68
69 typedef struct sftp_attributes_struct* sftp_attributes;
70 typedef struct sftp_client_message_struct* sftp_client_message;
71 typedef struct sftp_dir_struct* sftp_dir;
72 typedef struct sftp_ext_struct *sftp_ext;
73 typedef struct sftp_file_struct* sftp_file;
74 typedef struct sftp_message_struct* sftp_message;
75 typedef struct sftp_packet_struct* sftp_packet;
76 typedef struct sftp_request_queue_struct* sftp_request_queue;
77
92 typedef struct sftp_session_struct* sftp_session;
93 typedef struct sftp_status_message_struct* sftp_status_message;
94 typedef struct sftp_statvfs_struct* sftp_statvfs_t;
95 typedef struct sftp_limits_struct* sftp_limits_t;
96 typedef struct sftp_aio_struct* sftp_aio;
97 typedef struct sftp_name_id_map_struct *sftp_name_id_map;
98
99 struct sftp_session_struct {
100 ssh_session session;
101 ssh_channel channel;
102 int server_version;
103 int client_version;
104 int version;
105 sftp_request_queue queue;
106 uint32_t id_counter;
107 int errnum;
108 void **handles;
109 sftp_ext ext;
110 sftp_packet read_packet;
111 sftp_limits_t limits;
112 struct ssh_list *outstanding_ids;
113};
114
115 struct sftp_packet_struct {
116 sftp_session sftp;
117 uint8_t type;
118 ssh_buffer payload;
119};
120
121/* file handler */
122 struct sftp_file_struct {
123 sftp_session sftp;
124 char *name;
125 uint64_t offset;
126 ssh_string handle;
127 int eof;
128 int nonblocking;
129};
130
131 struct sftp_dir_struct {
132 sftp_session sftp;
133 char *name;
134 ssh_string handle; /* handle to directory */
135 ssh_buffer buffer; /* contains raw attributes from server which haven't been parsed */
136 uint32_t count; /* counts the number of following attributes structures into buffer */
137 int eof; /* end of directory listing */
138};
139
140 struct sftp_message_struct {
141 sftp_session sftp;
142 uint8_t packet_type;
143 ssh_buffer payload;
144 uint32_t id;
145};
146
147/* this is a bunch of all data that could be into a message */
148 struct sftp_client_message_struct {
149 sftp_session sftp;
150 uint8_t type;
151 uint32_t id;
152 char *filename; /* can be "path" */
153 uint32_t flags;
154 sftp_attributes attr;
155 ssh_string handle;
156 uint64_t offset;
157 uint32_t len;
158 int attr_num;
159 ssh_buffer attrbuf; /* used by sftp_reply_attrs */
160 ssh_string data; /* can be newpath of rename() */
161 ssh_buffer complete_message; /* complete message in case of retransmission*/
162 char *str_data; /* cstring version of data */
163 char *submessage; /* for extended messages */
164};
165
166 struct sftp_request_queue_struct {
167 sftp_request_queue next;
168 sftp_message message;
169};
170
171/* SSH_FXP_MESSAGE described into .7 page 26 */
172 struct sftp_status_message_struct {
173 uint32_t id;
174 uint32_t status;
175 ssh_string error_unused; /* not used anymore */
176 ssh_string lang_unused; /* not used anymore */
177 char *errormsg;
178 char *langmsg;
179};
180
181 struct sftp_attributes_struct {
182 char *name;
183 char *longname; /* ls -l output on openssh, not reliable else */
184 uint32_t flags;
185 uint8_t type;
186 uint64_t size;
187 uint32_t uid;
188 uint32_t gid;
189 char *owner; /* set if openssh and version 4 */
190 char *group; /* set if openssh and version 4 */
191 uint32_t permissions;
192 uint64_t atime64;
193 uint32_t atime;
194 uint32_t atime_nseconds;
195 uint64_t createtime;
196 uint32_t createtime_nseconds;
197 uint64_t mtime64;
198 uint32_t mtime;
199 uint32_t mtime_nseconds;
200 ssh_string acl;
201 uint32_t extended_count;
202 ssh_string extended_type;
203 ssh_string extended_data;
204};
205
209 struct sftp_statvfs_struct {
210 uint64_t f_bsize;
211 uint64_t f_frsize;
212 uint64_t f_blocks;
213 uint64_t f_bfree;
214 uint64_t f_bavail;
215 uint64_t f_files;
216 uint64_t f_ffree;
217 uint64_t f_favail;
218 uint64_t f_fsid;
219 uint64_t f_flag;
220 uint64_t f_namemax;
221};
222
226 struct sftp_limits_struct {
227 uint64_t max_packet_length;
228 uint64_t max_read_length;
229 uint64_t max_write_length;
230 uint64_t max_open_handles;
231};
232
238 struct sftp_name_id_map_struct {
240 uint32_t count;
241
243 uint32_t *ids;
244
246 char **names;
247};
248
266LIBSSH_API sftp_session sftp_new(ssh_session session);
267
281LIBSSH_API sftp_session sftp_new_channel(ssh_session session, ssh_channel channel);
282
283
289LIBSSH_API void sftp_free(sftp_session sftp);
290
303LIBSSH_API int sftp_init(sftp_session sftp);
304
317LIBSSH_API int sftp_get_error(sftp_session sftp);
318
327LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp);
328
338LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned int indexn);
339
351LIBSSH_API const char *sftp_extensions_get_data(sftp_session sftp, unsigned int indexn);
352
370LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name,
371 const char *data);
372
385LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path);
386
400LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir);
401
411LIBSSH_API int sftp_dir_eof(sftp_dir dir);
412
425LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path);
426
442LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path);
443
454LIBSSH_API sftp_attributes sftp_fstat(sftp_file file);
455
461LIBSSH_API void sftp_attributes_free(sftp_attributes file);
462
470LIBSSH_API int sftp_closedir(sftp_dir dir);
471
481LIBSSH_API int sftp_close(sftp_file file);
482
511LIBSSH_API sftp_file sftp_open(sftp_session session, const char *file, int accesstype,
512 mode_t mode);
513
519LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle);
520
526LIBSSH_API void sftp_file_set_blocking(sftp_file handle);
527
547LIBSSH_API ssize_t sftp_read(sftp_file file, void *buf, size_t count);
548
580SSH_DEPRECATED LIBSSH_API int sftp_async_read_begin(sftp_file file,
581 uint32_t len);
582
606SSH_DEPRECATED LIBSSH_API int sftp_async_read(sftp_file file,
607 void *data,
608 uint32_t len,
609 uint32_t id);
610
632LIBSSH_API ssize_t sftp_write(sftp_file file, const void *buf, size_t count);
633
650LIBSSH_API void sftp_aio_free(sftp_aio aio);
651#define SFTP_AIO_FREE(x) \
652 do { if(x != NULL) {sftp_aio_free(x); x = NULL;} } while(0)
653
717LIBSSH_API ssize_t sftp_aio_begin_read(sftp_file file,
718 size_t len,
719 sftp_aio *aio);
720
754LIBSSH_API ssize_t sftp_aio_wait_read(sftp_aio *aio,
755 void *buf,
756 size_t buf_size);
757
823LIBSSH_API ssize_t sftp_aio_begin_write(sftp_file file,
824 const void *buf,
825 size_t len,
826 sftp_aio *aio);
827
855LIBSSH_API ssize_t sftp_aio_wait_write(sftp_aio *aio);
856
866LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset);
867
878LIBSSH_API int sftp_seek64(sftp_file file, uint64_t new_offset);
879
889LIBSSH_API unsigned long sftp_tell(sftp_file file);
890
899LIBSSH_API uint64_t sftp_tell64(sftp_file file);
900
907LIBSSH_API void sftp_rewind(sftp_file file);
908
920LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file);
921
933LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory);
934
950LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode);
951
967LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname);
968
988LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr);
989
1010LIBSSH_API int
1011 sftp_lsetstat(sftp_session sftp, const char *file, sftp_attributes attr);
1012
1028LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group);
1029
1045LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode);
1046
1061LIBSSH_API int sftp_utimes(sftp_session sftp, const char *file, const struct timeval *times);
1062
1076LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest);
1077
1091LIBSSH_API char *sftp_readlink(sftp_session sftp, const char *path);
1092
1107LIBSSH_API int sftp_hardlink(sftp_session sftp, const char *oldpath, const char *newpath);
1108
1120LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path);
1121
1131LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file);
1132
1138LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o);
1139
1154LIBSSH_API int sftp_fsync(sftp_file file);
1155
1165LIBSSH_API sftp_limits_t sftp_limits(sftp_session sftp);
1166
1172LIBSSH_API void sftp_limits_free(sftp_limits_t limits);
1173
1185LIBSSH_API char *sftp_canonicalize_path(sftp_session sftp, const char *path);
1186
1194LIBSSH_API int sftp_server_version(sftp_session sftp);
1195
1207LIBSSH_API char *sftp_expand_path(sftp_session sftp, const char *path);
1208
1228LIBSSH_API char *sftp_home_directory(sftp_session sftp, const char *username);
1229
1238LIBSSH_API sftp_name_id_map sftp_name_id_map_new(uint32_t count);
1239
1245LIBSSH_API void sftp_name_id_map_free(sftp_name_id_map map);
1246
1278LIBSSH_API int sftp_get_users_groups_by_id(sftp_session sftp,
1279 sftp_name_id_map users_map,
1280 sftp_name_id_map groups_map);
1281
1282#ifdef WITH_SERVER
1292LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel chan);
1293
1301SSH_DEPRECATED LIBSSH_API int sftp_server_init(sftp_session sftp);
1302
1308LIBSSH_API void sftp_server_free(sftp_session sftp);
1309#endif /* WITH_SERVER */
1310
1311/* sftpserver.c */
1312
1313LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp);
1314LIBSSH_API void sftp_client_message_free(sftp_client_message msg);
1315LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg);
1316LIBSSH_API const char *sftp_client_message_get_filename(sftp_client_message msg);
1317LIBSSH_API void sftp_client_message_set_filename(sftp_client_message msg, const char *newname);
1318LIBSSH_API const char *sftp_client_message_get_data(sftp_client_message msg);
1319LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg);
1320LIBSSH_API const char *sftp_client_message_get_submessage(sftp_client_message msg);
1321LIBSSH_API int sftp_send_client_message(sftp_session sftp, sftp_client_message msg);
1322LIBSSH_API int sftp_reply_name(sftp_client_message msg, const char *name,
1323 sftp_attributes attr);
1324LIBSSH_API int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
1325LIBSSH_API ssh_string sftp_handle_alloc(sftp_session sftp, void *info);
1326LIBSSH_API int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
1327LIBSSH_API void *sftp_handle(sftp_session sftp, ssh_string handle);
1328LIBSSH_API int sftp_reply_status(sftp_client_message msg, uint32_t status, const char *message);
1329LIBSSH_API int sftp_reply_names_add(sftp_client_message msg, const char *file,
1330 const char *longname, sftp_attributes attr);
1331LIBSSH_API int sftp_reply_names(sftp_client_message msg);
1332LIBSSH_API int sftp_reply_data(sftp_client_message msg, const void *data, int len);
1333LIBSSH_API void sftp_handle_remove(sftp_session sftp, void *handle);
1334
1335/* SFTP commands and constants */
1336#define SSH_FXP_INIT 1
1337#define SSH_FXP_VERSION 2
1338#define SSH_FXP_OPEN 3
1339#define SSH_FXP_CLOSE 4
1340#define SSH_FXP_READ 5
1341#define SSH_FXP_WRITE 6
1342#define SSH_FXP_LSTAT 7
1343#define SSH_FXP_FSTAT 8
1344#define SSH_FXP_SETSTAT 9
1345#define SSH_FXP_FSETSTAT 10
1346#define SSH_FXP_OPENDIR 11
1347#define SSH_FXP_READDIR 12
1348#define SSH_FXP_REMOVE 13
1349#define SSH_FXP_MKDIR 14
1350#define SSH_FXP_RMDIR 15
1351#define SSH_FXP_REALPATH 16
1352#define SSH_FXP_STAT 17
1353#define SSH_FXP_RENAME 18
1354#define SSH_FXP_READLINK 19
1355#define SSH_FXP_SYMLINK 20
1356
1357#define SSH_FXP_STATUS 101
1358#define SSH_FXP_HANDLE 102
1359#define SSH_FXP_DATA 103
1360#define SSH_FXP_NAME 104
1361#define SSH_FXP_ATTRS 105
1362
1363#define SSH_FXP_EXTENDED 200
1364#define SSH_FXP_EXTENDED_REPLY 201
1365
1366/* attributes */
1367/* sftp draft is completely braindead : version 3 and 4 have different flags for same constants */
1368/* and even worst, version 4 has same flag for 2 different constants */
1369/* follow up : i won't develop any sftp4 compliant library before having a clarification */
1370
1371#define SSH_FILEXFER_ATTR_SIZE 0x00000001
1372#define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
1373#define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
1374#define SSH_FILEXFER_ATTR_ACMODTIME 0x00000008
1375#define SSH_FILEXFER_ATTR_CREATETIME 0x00000010
1376#define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020
1377#define SSH_FILEXFER_ATTR_ACL 0x00000040
1378#define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080
1379#define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
1380#define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
1381#define SSH_FILEXFER_ATTR_UIDGID 0x00000002
1382
1383/* types */
1384#define SSH_FILEXFER_TYPE_REGULAR 1
1385#define SSH_FILEXFER_TYPE_DIRECTORY 2
1386#define SSH_FILEXFER_TYPE_SYMLINK 3
1387#define SSH_FILEXFER_TYPE_SPECIAL 4
1388#define SSH_FILEXFER_TYPE_UNKNOWN 5
1389
1396
1398#define SSH_FX_OK 0
1400#define SSH_FX_EOF 1
1402#define SSH_FX_NO_SUCH_FILE 2
1404#define SSH_FX_PERMISSION_DENIED 3
1406#define SSH_FX_FAILURE 4
1408#define SSH_FX_BAD_MESSAGE 5
1410#define SSH_FX_NO_CONNECTION 6
1412#define SSH_FX_CONNECTION_LOST 7
1414#define SSH_FX_OP_UNSUPPORTED 8
1416#define SSH_FX_INVALID_HANDLE 9
1418#define SSH_FX_NO_SUCH_PATH 10
1420#define SSH_FX_FILE_ALREADY_EXISTS 11
1422#define SSH_FX_WRITE_PROTECT 12
1424#define SSH_FX_NO_MEDIA 13
1425
1427
1428/* file flags */
1429#define SSH_FXF_READ 0x01
1430#define SSH_FXF_WRITE 0x02
1431#define SSH_FXF_APPEND 0x04
1432#define SSH_FXF_CREAT 0x08
1433#define SSH_FXF_TRUNC 0x10
1434#define SSH_FXF_EXCL 0x20
1435#define SSH_FXF_TEXT 0x40
1436
1437/* file type flags */
1438#define SSH_S_IFMT 00170000
1439#define SSH_S_IFSOCK 0140000
1440#define SSH_S_IFLNK 0120000
1441#define SSH_S_IFREG 0100000
1442#define SSH_S_IFBLK 0060000
1443#define SSH_S_IFDIR 0040000
1444#define SSH_S_IFCHR 0020000
1445#define SSH_S_IFIFO 0010000
1446
1447/* rename flags */
1448#define SSH_FXF_RENAME_OVERWRITE 0x00000001
1449#define SSH_FXF_RENAME_ATOMIC 0x00000002
1450#define SSH_FXF_RENAME_NATIVE 0x00000004
1451
1452#define SFTP_OPEN SSH_FXP_OPEN
1453#define SFTP_CLOSE SSH_FXP_CLOSE
1454#define SFTP_READ SSH_FXP_READ
1455#define SFTP_WRITE SSH_FXP_WRITE
1456#define SFTP_LSTAT SSH_FXP_LSTAT
1457#define SFTP_FSTAT SSH_FXP_FSTAT
1458#define SFTP_SETSTAT SSH_FXP_SETSTAT
1459#define SFTP_FSETSTAT SSH_FXP_FSETSTAT
1460#define SFTP_OPENDIR SSH_FXP_OPENDIR
1461#define SFTP_READDIR SSH_FXP_READDIR
1462#define SFTP_REMOVE SSH_FXP_REMOVE
1463#define SFTP_MKDIR SSH_FXP_MKDIR
1464#define SFTP_RMDIR SSH_FXP_RMDIR
1465#define SFTP_REALPATH SSH_FXP_REALPATH
1466#define SFTP_STAT SSH_FXP_STAT
1467#define SFTP_RENAME SSH_FXP_RENAME
1468#define SFTP_READLINK SSH_FXP_READLINK
1469#define SFTP_SYMLINK SSH_FXP_SYMLINK
1470#define SFTP_EXTENDED SSH_FXP_EXTENDED
1471
1472/* openssh flags */
1473#define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
1474#define SSH_FXE_STATVFS_ST_NOSUID 0x2 /* no setuid */
1475
1476#ifdef __cplusplus
1477}
1478#endif
1479
1480#endif /* SFTP_H */
1481
sftp_fstat
LIBSSH_API sftp_attributes sftp_fstat(sftp_file file)
Get information about a file or directory from a file handle.
Definition sftp.c:3123
sftp_file_set_nonblocking
LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle)
Make the sftp communication for this file handle non blocking.
Definition sftp.c:1184
sftp_mkdir
LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode)
Create a directory.
Definition sftp.c:1749
sftp_rename
LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname)
Rename or move a file or directory.
Definition sftp.c:1852
sftp_reply_data
LIBSSH_API int sftp_reply_data(sftp_client_message msg, const void *data, int len)
Send an SFTP DATA reply.
Definition sftpserver.c:748
sftp_extensions_get_name
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:617
sftp_statvfs_free
LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o)
Free the memory of an allocated statvfs.
Definition sftp.c:2756
sftp_utimes
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:2167
sftp_reply_status
LIBSSH_API int sftp_reply_status(sftp_client_message msg, uint32_t status, const char *message)
Send an SFTP STATUS reply.
Definition sftpserver.c:701
sftp_reply_handle
LIBSSH_API int sftp_reply_handle(sftp_client_message msg, ssh_string handle)
Send an SFTP HANDLE reply for a client message.
Definition sftpserver.c:532
sftp_readdir
LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir)
Get a single file attributes structure of a directory.
Definition sftp.c:812
sftp_seek64
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:1574
sftp_reply_names_add
LIBSSH_API int sftp_reply_names_add(sftp_client_message msg, const char *file, const char *longname, sftp_attributes attr)
Add one name entry to a multi-name SFTP reply.
Definition sftpserver.c:605
sftp_closedir
LIBSSH_API int sftp_closedir(sftp_dir dir)
Close a directory handle opened by sftp_opendir().
Definition sftp.c:1039
sftp_client_message_get_filename
LIBSSH_API const char * sftp_client_message_get_filename(sftp_client_message msg)
Get the filename associated with an SFTP client message.
Definition sftpserver.c:369
sftp_close
LIBSSH_API int sftp_close(sftp_file file)
Close an open file handle.
Definition sftp.c:1020
sftp_client_message_get_submessage
LIBSSH_API const char * sftp_client_message_get_submessage(sftp_client_message msg)
Get the submessage name associated with an SFTP client message.
Definition sftpserver.c:438
sftp_name_id_map_new
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:3416
sftp_send_client_message
LIBSSH_API int sftp_send_client_message(sftp_session sftp, sftp_client_message msg)
Send an SFTP client message.
Definition sftpserver.c:338
sftp_client_message_get_data
LIBSSH_API const char * sftp_client_message_get_data(sftp_client_message msg)
Get the data field of an SFTP client message as a string.
Definition sftpserver.c:404
sftp_reply_name
LIBSSH_API int sftp_reply_name(sftp_client_message msg, const char *name, sftp_attributes attr)
Send an SFTP NAME reply for a client message.
Definition sftpserver.c:485
sftp_expand_path
LIBSSH_API char * sftp_expand_path(sftp_session sftp, const char *path)
Canonicalize path using expand-path@openssh.com extension.
Definition sftp.c:3195
sftp_server_init
SSH_DEPRECATED LIBSSH_API int sftp_server_init(sftp_session sftp)
Initialize the sftp server.
Definition sftp.c:291
sftp_aio_wait_read
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:142
sftp_server_free
LIBSSH_API void sftp_server_free(sftp_session sftp)
Close and deallocate a sftp server session.
Definition sftp.c:324
sftp_aio_wait_write
LIBSSH_API ssize_t sftp_aio_wait_write(sftp_aio *aio)
Wait for an asynchronous write to complete.
Definition sftp_aio.c:411
sftp_session
struct sftp_session_struct * sftp_session
SFTP session handle.
Definition sftp.h:92
sftp_extensions_get_count
LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp)
Get the count of extensions provided by the server.
Definition sftp.c:608
sftp_aio_free
LIBSSH_API void sftp_aio_free(sftp_aio aio)
Deallocate memory corresponding to a sftp aio handle.
Definition sftp_aio.c:48
sftp_get_error
LIBSSH_API int sftp_get_error(sftp_session sftp)
Get the last sftp error.
Definition sftp.c:448
sftp_tell
LIBSSH_API unsigned long sftp_tell(sftp_file file)
Report current byte position in file.
Definition sftp.c:1587
sftp_client_message_get_flags
LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg)
Get the flags associated with an SFTP client message.
Definition sftpserver.c:422
sftp_reply_names
LIBSSH_API int sftp_reply_names(sftp_client_message msg)
Send a multi-name SFTP reply.
Definition sftpserver.c:655
sftp_unlink
LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file)
Unlink (delete) a file.
Definition sftp.c:1602
sftp_lstat
LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path)
Get information about a file or directory.
Definition sftp.c:3119
sftp_client_message_free
LIBSSH_API void sftp_client_message_free(sftp_client_message msg)
Free an SFTP client message and its associated resources.
Definition sftpserver.c:453
sftp_async_read
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:1371
sftp_fstatvfs
LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file)
Get information about a mounted file system.
Definition sftp.c:2679
sftp_free
LIBSSH_API void sftp_free(sftp_session sftp)
Close and deallocate a sftp session.
Definition sftp.c:352
sftp_aio_begin_read
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
sftp_limits
LIBSSH_API sftp_limits_t sftp_limits(sftp_session sftp)
Get information about the various limits the server might impose.
Definition sftp.c:2911
sftp_lsetstat
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:2054
sftp_seek
LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset)
Seek to a specific location in a file.
Definition sftp.c:1561
sftp_get_client_message
LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp)
Reads the next SFTP client message from the session.
Definition sftpserver.c:297
sftp_server_new
LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel chan)
Create a new sftp server session.
Definition sftp.c:253
sftp_attributes_free
LIBSSH_API void sftp_attributes_free(sftp_attributes file)
Free a sftp attribute structure.
Definition sftp.c:930
sftp_limits_free
LIBSSH_API void sftp_limits_free(sftp_limits_t limits)
Free the memory of an allocated limits.
Definition sftp.c:2938
sftp_stat
LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path)
Get information about a file or directory.
Definition sftp.c:3115
sftp_extensions_get_data
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:636
sftp_tell64
LIBSSH_API uint64_t sftp_tell64(sftp_file file)
Report current byte position in file.
Definition sftp.c:1591
sftp_handle
LIBSSH_API void * sftp_handle(sftp_session sftp, ssh_string handle)
Resolve an SFTP handle to its stored info.
Definition sftpserver.c:935
sftp_home_directory
LIBSSH_API char * sftp_home_directory(sftp_session sftp, const char *username)
Get the specified user's home directory.
Definition sftp.c:3290
sftp_chown
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:2144
sftp_readlink
LIBSSH_API char * sftp_readlink(sftp_session sftp, const char *path)
Read the value of a symbolic link.
Definition sftp.c:2280
sftp_extension_supported
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:656
sftp_async_read_begin
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:1332
sftp_new_channel
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:193
sftp_open
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:1055
sftp_file_set_blocking
LIBSSH_API void sftp_file_set_blocking(sftp_file handle)
Make the sftp communication for this file handle blocking.
Definition sftp.c:1188
sftp_rmdir
LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory)
Remove a directory.
Definition sftp.c:1678
sftp_rewind
LIBSSH_API void sftp_rewind(sftp_file file)
Rewinds the position of the file pointer to the beginning of the file.
Definition sftp.c:1596
sftp_dir_eof
LIBSSH_API int sftp_dir_eof(sftp_dir dir)
Tell if the directory has reached EOF (End Of File).
Definition sftp.c:925
sftp_opendir
LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path)
Open a directory used to obtain directory entries.
Definition sftp.c:714
sftp_reply_attr
LIBSSH_API int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr)
Send an SFTP ATTRS reply for a client message.
Definition sftpserver.c:568
sftp_init
LIBSSH_API int sftp_init(sftp_session sftp)
Initialize the sftp protocol with the server.
Definition sftp.c:460
sftp_handle_alloc
LIBSSH_API ssh_string sftp_handle_alloc(sftp_session sftp, void *info)
Allocate a new SFTP handle slot.
Definition sftpserver.c:887
sftp_read
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:1195
sftp_server_version
LIBSSH_API int sftp_server_version(sftp_session sftp)
Get the version of the SFTP protocol supported by the server.
Definition sftp.c:807
sftp_setstat
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:1966
sftp_get_users_groups_by_id
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:3510
sftp_canonicalize_path
LIBSSH_API char * sftp_canonicalize_path(sftp_session sftp, const char *path)
Canonicalize a sftp path.
Definition sftp.c:2948
sftp_client_message_set_filename
LIBSSH_API void sftp_client_message_set_filename(sftp_client_message msg, const char *newname)
Set the filename associated with an SFTP client message.
Definition sftpserver.c:387
sftp_symlink
LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest)
Create a symbolic link.
Definition sftp.c:2184
sftp_aio_begin_write
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:309
sftp_new
LIBSSH_API sftp_session sftp_new(ssh_session session)
Creates a new sftp session.
Definition sftp.c:103
sftp_chmod
LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode)
Change permissions of a file.
Definition sftp.c:2157
sftp_statvfs
LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path)
Get information about a mounted file system.
Definition sftp.c:2498
sftp_fsync
LIBSSH_API int sftp_fsync(sftp_file file)
Synchronize a file's in-core state with storage device.
Definition sftp.c:2582
sftp_write
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:1453
sftp_name_id_map_free
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:3443
sftp_hardlink
LIBSSH_API int sftp_hardlink(sftp_session sftp, const char *oldpath, const char *newpath)
Create a hard link.
Definition sftp.c:2375
sftp_client_message_get_type
LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg)
Get the SFTP client message type.
Definition sftpserver.c:353
sftp_aio_struct
Definition sftp_aio.c:35
sftp_limits_struct
SFTP limits structure.
Definition sftp.h:226
sftp_limits_struct::max_write_length
uint64_t max_write_length
Definition sftp.h:229
sftp_limits_struct::max_open_handles
uint64_t max_open_handles
Definition sftp.h:230
sftp_limits_struct::max_read_length
uint64_t max_read_length
Definition sftp.h:228
sftp_name_id_map_struct
SFTP names map structure to store the mapping between ids and names.
Definition sftp.h:238
sftp_name_id_map_struct::ids
uint32_t * ids
Array of ids, ids[i] mapped to names[i].
Definition sftp.h:243
sftp_name_id_map_struct::names
char ** names
Array of names, names[i] mapped to ids[i].
Definition sftp.h:246
sftp_name_id_map_struct::count
uint32_t count
Count of name-id pairs in the map.
Definition sftp.h:240
sftp_statvfs_struct
SFTP statvfs structure.
Definition sftp.h:209
sftp_statvfs_struct::f_blocks
uint64_t f_blocks
Definition sftp.h:212
sftp_statvfs_struct::f_ffree
uint64_t f_ffree
Definition sftp.h:216
sftp_statvfs_struct::f_files
uint64_t f_files
Definition sftp.h:215
sftp_statvfs_struct::f_bavail
uint64_t f_bavail
Definition sftp.h:214
sftp_statvfs_struct::f_namemax
uint64_t f_namemax
Definition sftp.h:220
sftp_statvfs_struct::f_bfree
uint64_t f_bfree
Definition sftp.h:213
sftp_statvfs_struct::f_favail
uint64_t f_favail
Definition sftp.h:217
sftp_statvfs_struct::f_flag
uint64_t f_flag
Definition sftp.h:219
sftp_statvfs_struct::f_frsize
uint64_t f_frsize
Definition sftp.h:211
sftp_statvfs_struct::f_fsid
uint64_t f_fsid
Definition sftp.h:218