libssh 0.12.0
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
45extern "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
68#define LIBSFTP_VERSION 3
69
70typedef struct sftp_attributes_struct* sftp_attributes;
71typedef struct sftp_client_message_struct* sftp_client_message;
72typedef struct sftp_dir_struct* sftp_dir;
73typedef struct sftp_ext_struct *sftp_ext;
74typedef struct sftp_file_struct* sftp_file;
75typedef struct sftp_message_struct* sftp_message;
76typedef struct sftp_packet_struct* sftp_packet;
77typedef struct sftp_request_queue_struct* sftp_request_queue;
78
93typedef struct sftp_session_struct* sftp_session;
94
105typedef struct sftp_status_message_struct* sftp_status_message;
106
120typedef struct sftp_statvfs_struct* sftp_statvfs_t;
121
134
150typedef struct sftp_aio_struct* sftp_aio;
151
165
166struct sftp_session_struct {
167 ssh_session session;
168 ssh_channel channel;
169 int server_version;
170 int client_version;
171 int version;
172 sftp_request_queue queue;
173 uint32_t id_counter;
174 int errnum;
175 void **handles;
176 sftp_ext ext;
177 sftp_packet read_packet;
178 sftp_limits_t limits;
179};
180
181struct sftp_packet_struct {
182 sftp_session sftp;
183 uint8_t type;
184 ssh_buffer payload;
185};
186
187/* file handler */
188struct sftp_file_struct {
189 sftp_session sftp;
190 char *name;
191 uint64_t offset;
192 ssh_string handle;
193 int eof;
194 int nonblocking;
195};
196
197struct sftp_dir_struct {
198 sftp_session sftp;
199 char *name;
200 ssh_string handle; /* handle to directory */
201 ssh_buffer buffer; /* contains raw attributes from server which haven't been parsed */
202 uint32_t count; /* counts the number of following attributes structures into buffer */
203 int eof; /* end of directory listing */
204};
205
206struct sftp_message_struct {
207 sftp_session sftp;
208 uint8_t packet_type;
209 ssh_buffer payload;
210 uint32_t id;
211};
212
213/* this is a bunch of all data that could be into a message */
214struct sftp_client_message_struct {
215 sftp_session sftp;
216 uint8_t type;
217 uint32_t id;
218 char *filename; /* can be "path" */
219 uint32_t flags;
220 sftp_attributes attr;
221 ssh_string handle;
222 uint64_t offset;
223 uint32_t len;
224 int attr_num;
225 ssh_buffer attrbuf; /* used by sftp_reply_attrs */
226 ssh_string data; /* can be newpath of rename() */
227 ssh_buffer complete_message; /* complete message in case of retransmission*/
228 char *str_data; /* cstring version of data */
229 char *submessage; /* for extended messages */
230};
231
232struct sftp_request_queue_struct {
233 sftp_request_queue next;
234 sftp_message message;
235};
236
237/* SSH_FXP_MESSAGE described into .7 page 26 */
238struct sftp_status_message_struct {
239 uint32_t id;
240 uint32_t status;
241 ssh_string error_unused; /* not used anymore */
242 ssh_string lang_unused; /* not used anymore */
243 char *errormsg;
244 char *langmsg;
245};
246
259 char *name;
260
262 char *longname;
263
265 uint32_t flags;
266
268 uint8_t type;
269
271 uint64_t size;
272
274 uint32_t uid;
275
277 uint32_t gid;
278
284 char *owner;
285
291 char *group;
292
294 uint32_t permissions;
295
300 uint64_t atime64;
301
306 uint32_t atime;
307
313
318 uint64_t createtime;
319
325
330 uint64_t mtime64;
331
336 uint32_t mtime;
337
343
345 ssh_string acl;
346
349
351 ssh_string extended_type;
352
354 ssh_string extended_data;
355};
356
362 uint64_t f_bsize;
363
365 uint64_t f_frsize;
366
368 uint64_t f_blocks;
369
371 uint64_t f_bfree;
372
374 uint64_t f_bavail;
375
377 uint64_t f_files;
378
380 uint64_t f_ffree;
381
383 uint64_t f_favail;
384
386 uint64_t f_fsid;
387
389 uint64_t f_flag;
390
392 uint64_t f_namemax;
393};
394
401
404
407
410};
411
419 uint32_t count;
420
422 uint32_t *ids;
423
425 char **names;
426};
427
445LIBSSH_API sftp_session sftp_new(ssh_session session);
446
460LIBSSH_API sftp_session sftp_new_channel(ssh_session session, ssh_channel channel);
461
467LIBSSH_API void sftp_free(sftp_session sftp);
468
481LIBSSH_API int sftp_init(sftp_session sftp);
482
495LIBSSH_API int sftp_get_error(sftp_session sftp);
496
505LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp);
506
516LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned int indexn);
517
529LIBSSH_API const char *sftp_extensions_get_data(sftp_session sftp, unsigned int indexn);
530
548LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name,
549 const char *data);
550
563LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path);
564
578LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir);
579
589LIBSSH_API int sftp_dir_eof(sftp_dir dir);
590
603LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path);
604
620LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path);
621
632LIBSSH_API sftp_attributes sftp_fstat(sftp_file file);
633
639LIBSSH_API void sftp_attributes_free(sftp_attributes file);
640
648LIBSSH_API int sftp_closedir(sftp_dir dir);
649
659LIBSSH_API int sftp_close(sftp_file file);
660
689LIBSSH_API sftp_file sftp_open(sftp_session session, const char *file, int accesstype,
690 mode_t mode);
691
697LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle);
698
704LIBSSH_API void sftp_file_set_blocking(sftp_file handle);
705
725LIBSSH_API ssize_t sftp_read(sftp_file file, void *buf, size_t count);
726
758SSH_DEPRECATED LIBSSH_API int sftp_async_read_begin(sftp_file file,
759 uint32_t len);
760
784SSH_DEPRECATED LIBSSH_API int sftp_async_read(sftp_file file,
785 void *data,
786 uint32_t len,
787 uint32_t id);
788
810LIBSSH_API ssize_t sftp_write(sftp_file file, const void *buf, size_t count);
811
828LIBSSH_API void sftp_aio_free(sftp_aio aio);
829#define SFTP_AIO_FREE(x) \
830 do { if(x != NULL) {sftp_aio_free(x); x = NULL;} } while(0)
831
895LIBSSH_API ssize_t sftp_aio_begin_read(sftp_file file,
896 size_t len,
897 sftp_aio *aio);
898
932LIBSSH_API ssize_t sftp_aio_wait_read(sftp_aio *aio,
933 void *buf,
934 size_t buf_size);
935
1001LIBSSH_API ssize_t sftp_aio_begin_write(sftp_file file,
1002 const void *buf,
1003 size_t len,
1004 sftp_aio *aio);
1005
1033LIBSSH_API ssize_t sftp_aio_wait_write(sftp_aio *aio);
1034
1044LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset);
1045
1056LIBSSH_API int sftp_seek64(sftp_file file, uint64_t new_offset);
1057
1067LIBSSH_API unsigned long sftp_tell(sftp_file file);
1068
1077LIBSSH_API uint64_t sftp_tell64(sftp_file file);
1078
1085LIBSSH_API void sftp_rewind(sftp_file file);
1086
1098LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file);
1099
1111LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory);
1112
1128LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode);
1129
1145LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname);
1146
1166LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr);
1167
1188LIBSSH_API int
1189sftp_lsetstat(sftp_session sftp, const char *file, sftp_attributes attr);
1190
1206LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group);
1207
1223LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode);
1224
1239LIBSSH_API int sftp_utimes(sftp_session sftp, const char *file, const struct timeval *times);
1240
1254LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest);
1255
1269LIBSSH_API char *sftp_readlink(sftp_session sftp, const char *path);
1270
1285LIBSSH_API int sftp_hardlink(sftp_session sftp, const char *oldpath, const char *newpath);
1286
1298LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path);
1299
1309LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file);
1310
1316LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o);
1317
1332LIBSSH_API int sftp_fsync(sftp_file file);
1333
1343LIBSSH_API sftp_limits_t sftp_limits(sftp_session sftp);
1344
1350LIBSSH_API void sftp_limits_free(sftp_limits_t limits);
1351
1363LIBSSH_API char *sftp_canonicalize_path(sftp_session sftp, const char *path);
1364
1372LIBSSH_API int sftp_server_version(sftp_session sftp);
1373
1385LIBSSH_API char *sftp_expand_path(sftp_session sftp, const char *path);
1386
1406LIBSSH_API char *sftp_home_directory(sftp_session sftp, const char *username);
1407
1416LIBSSH_API sftp_name_id_map sftp_name_id_map_new(uint32_t count);
1417
1423LIBSSH_API void sftp_name_id_map_free(sftp_name_id_map map);
1424
1456LIBSSH_API int sftp_get_users_groups_by_id(sftp_session sftp,
1457 sftp_name_id_map users_map,
1458 sftp_name_id_map groups_map);
1459
1460#ifdef WITH_SERVER
1470LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel chan);
1471
1479SSH_DEPRECATED LIBSSH_API int sftp_server_init(sftp_session sftp);
1480
1486LIBSSH_API void sftp_server_free(sftp_session sftp);
1487#endif /* WITH_SERVER */
1488
1489/* sftpserver.c */
1490
1491LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp);
1492LIBSSH_API void sftp_client_message_free(sftp_client_message msg);
1493LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg);
1494LIBSSH_API const char *sftp_client_message_get_filename(sftp_client_message msg);
1495LIBSSH_API void sftp_client_message_set_filename(sftp_client_message msg, const char *newname);
1496LIBSSH_API const char *sftp_client_message_get_data(sftp_client_message msg);
1497LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg);
1498LIBSSH_API const char *sftp_client_message_get_submessage(sftp_client_message msg);
1499LIBSSH_API int sftp_send_client_message(sftp_session sftp, sftp_client_message msg);
1500LIBSSH_API int sftp_reply_name(sftp_client_message msg, const char *name,
1501 sftp_attributes attr);
1502LIBSSH_API int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
1503LIBSSH_API ssh_string sftp_handle_alloc(sftp_session sftp, void *info);
1504LIBSSH_API int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
1505LIBSSH_API void *sftp_handle(sftp_session sftp, ssh_string handle);
1506LIBSSH_API int sftp_reply_status(sftp_client_message msg, uint32_t status, const char *message);
1507LIBSSH_API int sftp_reply_names_add(sftp_client_message msg, const char *file,
1508 const char *longname, sftp_attributes attr);
1509LIBSSH_API int sftp_reply_names(sftp_client_message msg);
1510LIBSSH_API int sftp_reply_data(sftp_client_message msg, const void *data, int len);
1511LIBSSH_API void sftp_handle_remove(sftp_session sftp, void *handle);
1512
1513/* SFTP commands and constants */
1514#define SSH_FXP_INIT 1
1515#define SSH_FXP_VERSION 2
1516#define SSH_FXP_OPEN 3
1517#define SSH_FXP_CLOSE 4
1518#define SSH_FXP_READ 5
1519#define SSH_FXP_WRITE 6
1520#define SSH_FXP_LSTAT 7
1521#define SSH_FXP_FSTAT 8
1522#define SSH_FXP_SETSTAT 9
1523#define SSH_FXP_FSETSTAT 10
1524#define SSH_FXP_OPENDIR 11
1525#define SSH_FXP_READDIR 12
1526#define SSH_FXP_REMOVE 13
1527#define SSH_FXP_MKDIR 14
1528#define SSH_FXP_RMDIR 15
1529#define SSH_FXP_REALPATH 16
1530#define SSH_FXP_STAT 17
1531#define SSH_FXP_RENAME 18
1532#define SSH_FXP_READLINK 19
1533#define SSH_FXP_SYMLINK 20
1534
1535#define SSH_FXP_STATUS 101
1536#define SSH_FXP_HANDLE 102
1537#define SSH_FXP_DATA 103
1538#define SSH_FXP_NAME 104
1539#define SSH_FXP_ATTRS 105
1540
1541#define SSH_FXP_EXTENDED 200
1542#define SSH_FXP_EXTENDED_REPLY 201
1543
1544/* attributes */
1545/* sftp draft is completely braindead : version 3 and 4 have different flags for same constants */
1546/* and even worst, version 4 has same flag for 2 different constants */
1547/* follow up : i won't develop any sftp4 compliant library before having a clarification */
1548
1549#define SSH_FILEXFER_ATTR_SIZE 0x00000001
1550#define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
1551#define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
1552#define SSH_FILEXFER_ATTR_ACMODTIME 0x00000008
1553#define SSH_FILEXFER_ATTR_CREATETIME 0x00000010
1554#define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020
1555#define SSH_FILEXFER_ATTR_ACL 0x00000040
1556#define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080
1557#define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
1558#define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
1559#define SSH_FILEXFER_ATTR_UIDGID 0x00000002
1560
1561/* types */
1562#define SSH_FILEXFER_TYPE_REGULAR 1
1563#define SSH_FILEXFER_TYPE_DIRECTORY 2
1564#define SSH_FILEXFER_TYPE_SYMLINK 3
1565#define SSH_FILEXFER_TYPE_SPECIAL 4
1566#define SSH_FILEXFER_TYPE_UNKNOWN 5
1567
1574
1576#define SSH_FX_OK 0
1578#define SSH_FX_EOF 1
1580#define SSH_FX_NO_SUCH_FILE 2
1582#define SSH_FX_PERMISSION_DENIED 3
1584#define SSH_FX_FAILURE 4
1586#define SSH_FX_BAD_MESSAGE 5
1588#define SSH_FX_NO_CONNECTION 6
1590#define SSH_FX_CONNECTION_LOST 7
1592#define SSH_FX_OP_UNSUPPORTED 8
1594#define SSH_FX_INVALID_HANDLE 9
1596#define SSH_FX_NO_SUCH_PATH 10
1598#define SSH_FX_FILE_ALREADY_EXISTS 11
1600#define SSH_FX_WRITE_PROTECT 12
1602#define SSH_FX_NO_MEDIA 13
1603
1605
1606/* file flags */
1607#define SSH_FXF_READ 0x01
1608#define SSH_FXF_WRITE 0x02
1609#define SSH_FXF_APPEND 0x04
1610#define SSH_FXF_CREAT 0x08
1611#define SSH_FXF_TRUNC 0x10
1612#define SSH_FXF_EXCL 0x20
1613#define SSH_FXF_TEXT 0x40
1614
1615/* file type flags */
1616#define SSH_S_IFMT 00170000
1617#define SSH_S_IFSOCK 0140000
1618#define SSH_S_IFLNK 0120000
1619#define SSH_S_IFREG 0100000
1620#define SSH_S_IFBLK 0060000
1621#define SSH_S_IFDIR 0040000
1622#define SSH_S_IFCHR 0020000
1623#define SSH_S_IFIFO 0010000
1624
1625/* rename flags */
1626#define SSH_FXF_RENAME_OVERWRITE 0x00000001
1627#define SSH_FXF_RENAME_ATOMIC 0x00000002
1628#define SSH_FXF_RENAME_NATIVE 0x00000004
1629
1630#define SFTP_OPEN SSH_FXP_OPEN
1631#define SFTP_CLOSE SSH_FXP_CLOSE
1632#define SFTP_READ SSH_FXP_READ
1633#define SFTP_WRITE SSH_FXP_WRITE
1634#define SFTP_LSTAT SSH_FXP_LSTAT
1635#define SFTP_FSTAT SSH_FXP_FSTAT
1636#define SFTP_SETSTAT SSH_FXP_SETSTAT
1637#define SFTP_FSETSTAT SSH_FXP_FSETSTAT
1638#define SFTP_OPENDIR SSH_FXP_OPENDIR
1639#define SFTP_READDIR SSH_FXP_READDIR
1640#define SFTP_REMOVE SSH_FXP_REMOVE
1641#define SFTP_MKDIR SSH_FXP_MKDIR
1642#define SFTP_RMDIR SSH_FXP_RMDIR
1643#define SFTP_REALPATH SSH_FXP_REALPATH
1644#define SFTP_STAT SSH_FXP_STAT
1645#define SFTP_RENAME SSH_FXP_RENAME
1646#define SFTP_READLINK SSH_FXP_READLINK
1647#define SFTP_SYMLINK SSH_FXP_SYMLINK
1648#define SFTP_EXTENDED SSH_FXP_EXTENDED
1649
1650/* openssh flags */
1652#define SSH_FXE_STATVFS_ST_RDONLY 0x1 /* read-only */
1654#define SSH_FXE_STATVFS_ST_NOSUID 0x2 /* no setuid */
1655
1656#ifdef __cplusplus
1657}
1658#endif
1659
1660#endif /* SFTP_H */
1661
LIBSSH_API void sftp_handle_remove(sftp_session sftp, void *handle)
Remove an internal SFTP object-handle mapping.
Definition sftpserver.c:976
LIBSSH_API sftp_attributes sftp_fstat(sftp_file file)
Get information about a file or directory from a file handle.
Definition sftp.c:3034
LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle)
Make the sftp communication for this file handle non blocking.
Definition sftp.c:1150
LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode)
Create a directory.
Definition sftp.c:1700
struct sftp_limits_struct * sftp_limits_t
Handle for SFTP server limits information.
Definition sftp.h:133
LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname)
Rename or move a file or directory.
Definition sftp.c:1800
LIBSSH_API int sftp_reply_data(sftp_client_message msg, const void *data, int len)
Send an SFTP DATA reply.
Definition sftpserver.c:755
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:596
LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o)
Free the memory of an allocated statvfs.
Definition sftp.c:2676
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:2106
LIBSSH_API int sftp_reply_status(sftp_client_message msg, uint32_t status, const char *message)
Send an SFTP STATUS reply.
Definition sftpserver.c:705
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
LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir)
Get a single file attributes structure of a directory.
Definition sftp.c:788
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:1531
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:606
LIBSSH_API int sftp_closedir(sftp_dir dir)
Close a directory handle opened by sftp_opendir().
Definition sftp.c:1009
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:366
LIBSSH_API int sftp_close(sftp_file file)
Close an open file handle.
Definition sftp.c:990
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:435
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:3318
LIBSSH_API int sftp_send_client_message(sftp_session sftp, sftp_client_message msg)
Send an SFTP client message.
Definition sftpserver.c:335
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:401
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:482
LIBSSH_API char * sftp_expand_path(sftp_session sftp, const char *path)
Canonicalize path using expand-path@openssh.com extension.
Definition sftp.c:3103
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
struct sftp_session_struct * sftp_session
SFTP session handle.
Definition sftp.h:93
LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp)
Get the count of extensions provided by the server.
Definition sftp.c:587
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:1544
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:419
LIBSSH_API int sftp_reply_names(sftp_client_message msg)
Send a multi-name SFTP reply.
Definition sftpserver.c:656
LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file)
Unlink (delete) a file.
Definition sftp.c:1559
LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path)
Get information about a file or directory.
Definition sftp.c:3030
LIBSSH_API void sftp_client_message_free(sftp_client_message msg)
Free an SFTP client message and its associated resources.
Definition sftpserver.c:450
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:1331
LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file)
Get information about a mounted file system.
Definition sftp.c:2602
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:2828
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:1996
LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset)
Seek to a specific location in a file.
Definition sftp.c:1518
LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp)
Reads the next SFTP client message from the session.
Definition sftpserver.c:294
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:903
LIBSSH_API void sftp_limits_free(sftp_limits_t limits)
Free the memory of an allocated limits.
Definition sftp.c:2855
LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path)
Get information about a file or directory.
Definition sftp.c:3026
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:615
LIBSSH_API uint64_t sftp_tell64(sftp_file file)
Report current byte position in file.
Definition sftp.c:1548
LIBSSH_API void * sftp_handle(sftp_session sftp, ssh_string handle)
Resolve an SFTP handle to its stored info.
Definition sftpserver.c:940
LIBSSH_API char * sftp_home_directory(sftp_session sftp, const char *username)
Get the specified user's home directory.
Definition sftp.c:3195
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:2083
LIBSSH_API char * sftp_readlink(sftp_session sftp, const char *path)
Read the value of a symbolic link.
Definition sftp.c:2216
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:635
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:1295
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:1025
LIBSSH_API void sftp_file_set_blocking(sftp_file handle)
Make the sftp communication for this file handle blocking.
Definition sftp.c:1154
LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory)
Remove a directory.
Definition sftp.c:1632
LIBSSH_API void sftp_rewind(sftp_file file)
Rewinds the position of the file pointer to the beginning of the file.
Definition sftp.c:1553
LIBSSH_API int sftp_dir_eof(sftp_dir dir)
Tell if the directory has reached EOF (End Of File).
Definition sftp.c:898
LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path)
Open a directory used to obtain directory entries.
Definition sftp.c:693
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:569
LIBSSH_API int sftp_init(sftp_session sftp)
Initialize the sftp protocol with the server.
Definition sftp.c:439
LIBSSH_API ssh_string sftp_handle_alloc(sftp_session sftp, void *info)
Allocate a new SFTP handle slot.
Definition sftpserver.c:892
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:1161
LIBSSH_API int sftp_server_version(sftp_session sftp)
Get the version of the SFTP protocol supported by the server.
Definition sftp.c:783
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:1911
struct sftp_aio_struct * sftp_aio
Handle for an asynchronous SFTP I/O operation.
Definition sftp.h:150
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:3412
LIBSSH_API char * sftp_canonicalize_path(sftp_session sftp, const char *path)
Canonicalize a sftp path.
Definition sftp.c:2865
struct sftp_name_id_map_struct * sftp_name_id_map
Handle for an SFTP name-to-id mapping.
Definition sftp.h:164
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:384
LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest)
Create a symbolic link.
Definition sftp.c:2123
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:2096
LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path)
Get information about a mounted file system.
Definition sftp.c:2427
LIBSSH_API int sftp_fsync(sftp_file file)
Synchronize a file's in-core state with storage device.
Definition sftp.c:2508
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:1413
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:3345
LIBSSH_API int sftp_hardlink(sftp_session sftp, const char *oldpath, const char *newpath)
Create a hard link.
Definition sftp.c:2307
LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg)
Get the SFTP client message type.
Definition sftpserver.c:350
Definition sftp_aio.c:35
SFTP file attributes structure.
Definition sftp.h:257
uint32_t gid
Definition sftp.h:277
ssh_string acl
Definition sftp.h:345
uint32_t extended_count
Definition sftp.h:348
uint32_t createtime_nseconds
Definition sftp.h:324
uint64_t mtime64
Definition sftp.h:330
uint32_t flags
Definition sftp.h:265
uint32_t atime_nseconds
Definition sftp.h:312
uint32_t mtime
Definition sftp.h:336
uint8_t type
Definition sftp.h:268
uint32_t uid
Definition sftp.h:274
uint32_t mtime_nseconds
Definition sftp.h:342
uint32_t permissions
Definition sftp.h:294
char * owner
Definition sftp.h:284
char * group
Definition sftp.h:291
ssh_string extended_data
Definition sftp.h:354
char * longname
Definition sftp.h:262
char * name
Definition sftp.h:259
ssh_string extended_type
Definition sftp.h:351
uint64_t createtime
Definition sftp.h:318
uint32_t atime
Definition sftp.h:306
uint64_t size
Definition sftp.h:271
uint64_t atime64
Definition sftp.h:300
SFTP limits structure.
Definition sftp.h:398
uint64_t max_write_length
Definition sftp.h:406
uint64_t max_open_handles
Definition sftp.h:409
uint64_t max_packet_length
Definition sftp.h:400
uint64_t max_read_length
Definition sftp.h:403
SFTP names map structure to store the mapping between ids and names.
Definition sftp.h:417
uint32_t * ids
Array of ids, ids[i] mapped to names[i].
Definition sftp.h:422
char ** names
Array of names, names[i] mapped to ids[i].
Definition sftp.h:425
uint32_t count
Count of name-id pairs in the map.
Definition sftp.h:419
SFTP statvfs structure.
Definition sftp.h:360
uint64_t f_blocks
Definition sftp.h:368
uint64_t f_ffree
Definition sftp.h:380
uint64_t f_files
Definition sftp.h:377
uint64_t f_bavail
Definition sftp.h:374
uint64_t f_namemax
Definition sftp.h:392
uint64_t f_bfree
Definition sftp.h:371
uint64_t f_favail
Definition sftp.h:383
uint64_t f_flag
Definition sftp.h:389
uint64_t f_bsize
Definition sftp.h:362
uint64_t f_frsize
Definition sftp.h:365
uint64_t f_fsid
Definition sftp.h:386