File indexing completed on 2025-01-17 09:55:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 #ifndef LIBSSH2_SFTP_H
0041 #define LIBSSH2_SFTP_H 1
0042
0043 #include "libssh2.h"
0044
0045 #ifndef _WIN32
0046 #include <unistd.h>
0047 #endif
0048
0049 #ifdef __cplusplus
0050 extern "C" {
0051 #endif
0052
0053
0054
0055
0056
0057
0058 #define LIBSSH2_SFTP_VERSION 3
0059
0060 typedef struct _LIBSSH2_SFTP LIBSSH2_SFTP;
0061 typedef struct _LIBSSH2_SFTP_HANDLE LIBSSH2_SFTP_HANDLE;
0062 typedef struct _LIBSSH2_SFTP_ATTRIBUTES LIBSSH2_SFTP_ATTRIBUTES;
0063 typedef struct _LIBSSH2_SFTP_STATVFS LIBSSH2_SFTP_STATVFS;
0064
0065
0066 #define LIBSSH2_SFTP_OPENFILE 0
0067 #define LIBSSH2_SFTP_OPENDIR 1
0068
0069
0070 #define LIBSSH2_SFTP_RENAME_OVERWRITE 0x00000001
0071 #define LIBSSH2_SFTP_RENAME_ATOMIC 0x00000002
0072 #define LIBSSH2_SFTP_RENAME_NATIVE 0x00000004
0073
0074
0075 #define LIBSSH2_SFTP_STAT 0
0076 #define LIBSSH2_SFTP_LSTAT 1
0077 #define LIBSSH2_SFTP_SETSTAT 2
0078
0079
0080 #define LIBSSH2_SFTP_SYMLINK 0
0081 #define LIBSSH2_SFTP_READLINK 1
0082 #define LIBSSH2_SFTP_REALPATH 2
0083
0084
0085 #define LIBSSH2_SFTP_DEFAULT_MODE -1
0086
0087
0088 #define LIBSSH2_SFTP_ATTR_SIZE 0x00000001
0089 #define LIBSSH2_SFTP_ATTR_UIDGID 0x00000002
0090 #define LIBSSH2_SFTP_ATTR_PERMISSIONS 0x00000004
0091 #define LIBSSH2_SFTP_ATTR_ACMODTIME 0x00000008
0092 #define LIBSSH2_SFTP_ATTR_EXTENDED 0x80000000
0093
0094
0095 #define LIBSSH2_SFTP_ST_RDONLY 0x00000001
0096 #define LIBSSH2_SFTP_ST_NOSUID 0x00000002
0097
0098 struct _LIBSSH2_SFTP_ATTRIBUTES {
0099
0100
0101
0102 unsigned long flags;
0103
0104 libssh2_uint64_t filesize;
0105 unsigned long uid, gid;
0106 unsigned long permissions;
0107 unsigned long atime, mtime;
0108 };
0109
0110 struct _LIBSSH2_SFTP_STATVFS {
0111 libssh2_uint64_t f_bsize;
0112 libssh2_uint64_t f_frsize;
0113 libssh2_uint64_t f_blocks;
0114 libssh2_uint64_t f_bfree;
0115 libssh2_uint64_t f_bavail;
0116 libssh2_uint64_t f_files;
0117 libssh2_uint64_t f_ffree;
0118 libssh2_uint64_t f_favail;
0119 libssh2_uint64_t f_fsid;
0120 libssh2_uint64_t f_flag;
0121 libssh2_uint64_t f_namemax;
0122 };
0123
0124
0125 #define LIBSSH2_SFTP_TYPE_REGULAR 1
0126 #define LIBSSH2_SFTP_TYPE_DIRECTORY 2
0127 #define LIBSSH2_SFTP_TYPE_SYMLINK 3
0128 #define LIBSSH2_SFTP_TYPE_SPECIAL 4
0129 #define LIBSSH2_SFTP_TYPE_UNKNOWN 5
0130 #define LIBSSH2_SFTP_TYPE_SOCKET 6
0131 #define LIBSSH2_SFTP_TYPE_CHAR_DEVICE 7
0132 #define LIBSSH2_SFTP_TYPE_BLOCK_DEVICE 8
0133 #define LIBSSH2_SFTP_TYPE_FIFO 9
0134
0135
0136
0137
0138
0139
0140
0141
0142 #define LIBSSH2_SFTP_S_IFMT 0170000
0143 #define LIBSSH2_SFTP_S_IFIFO 0010000
0144 #define LIBSSH2_SFTP_S_IFCHR 0020000
0145 #define LIBSSH2_SFTP_S_IFDIR 0040000
0146 #define LIBSSH2_SFTP_S_IFBLK 0060000
0147 #define LIBSSH2_SFTP_S_IFREG 0100000
0148 #define LIBSSH2_SFTP_S_IFLNK 0120000
0149 #define LIBSSH2_SFTP_S_IFSOCK 0140000
0150
0151
0152
0153 #define LIBSSH2_SFTP_S_IRWXU 0000700
0154 #define LIBSSH2_SFTP_S_IRUSR 0000400
0155 #define LIBSSH2_SFTP_S_IWUSR 0000200
0156 #define LIBSSH2_SFTP_S_IXUSR 0000100
0157
0158 #define LIBSSH2_SFTP_S_IRWXG 0000070
0159 #define LIBSSH2_SFTP_S_IRGRP 0000040
0160 #define LIBSSH2_SFTP_S_IWGRP 0000020
0161 #define LIBSSH2_SFTP_S_IXGRP 0000010
0162
0163 #define LIBSSH2_SFTP_S_IRWXO 0000007
0164 #define LIBSSH2_SFTP_S_IROTH 0000004
0165 #define LIBSSH2_SFTP_S_IWOTH 0000002
0166 #define LIBSSH2_SFTP_S_IXOTH 0000001
0167
0168
0169 #define LIBSSH2_SFTP_S_ISLNK(m) \
0170 (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFLNK)
0171 #define LIBSSH2_SFTP_S_ISREG(m) \
0172 (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFREG)
0173 #define LIBSSH2_SFTP_S_ISDIR(m) \
0174 (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFDIR)
0175 #define LIBSSH2_SFTP_S_ISCHR(m) \
0176 (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFCHR)
0177 #define LIBSSH2_SFTP_S_ISBLK(m) \
0178 (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFBLK)
0179 #define LIBSSH2_SFTP_S_ISFIFO(m) \
0180 (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFIFO)
0181 #define LIBSSH2_SFTP_S_ISSOCK(m) \
0182 (((m) & LIBSSH2_SFTP_S_IFMT) == LIBSSH2_SFTP_S_IFSOCK)
0183
0184
0185
0186 #define LIBSSH2_FXF_READ 0x00000001
0187 #define LIBSSH2_FXF_WRITE 0x00000002
0188 #define LIBSSH2_FXF_APPEND 0x00000004
0189 #define LIBSSH2_FXF_CREAT 0x00000008
0190 #define LIBSSH2_FXF_TRUNC 0x00000010
0191 #define LIBSSH2_FXF_EXCL 0x00000020
0192
0193
0194 #define LIBSSH2_FX_OK 0UL
0195 #define LIBSSH2_FX_EOF 1UL
0196 #define LIBSSH2_FX_NO_SUCH_FILE 2UL
0197 #define LIBSSH2_FX_PERMISSION_DENIED 3UL
0198 #define LIBSSH2_FX_FAILURE 4UL
0199 #define LIBSSH2_FX_BAD_MESSAGE 5UL
0200 #define LIBSSH2_FX_NO_CONNECTION 6UL
0201 #define LIBSSH2_FX_CONNECTION_LOST 7UL
0202 #define LIBSSH2_FX_OP_UNSUPPORTED 8UL
0203 #define LIBSSH2_FX_INVALID_HANDLE 9UL
0204 #define LIBSSH2_FX_NO_SUCH_PATH 10UL
0205 #define LIBSSH2_FX_FILE_ALREADY_EXISTS 11UL
0206 #define LIBSSH2_FX_WRITE_PROTECT 12UL
0207 #define LIBSSH2_FX_NO_MEDIA 13UL
0208 #define LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM 14UL
0209 #define LIBSSH2_FX_QUOTA_EXCEEDED 15UL
0210 #define LIBSSH2_FX_UNKNOWN_PRINCIPLE 16UL
0211 #define LIBSSH2_FX_UNKNOWN_PRINCIPAL 16UL
0212 #define LIBSSH2_FX_LOCK_CONFlICT 17UL
0213 #define LIBSSH2_FX_LOCK_CONFLICT 17UL
0214 #define LIBSSH2_FX_DIR_NOT_EMPTY 18UL
0215 #define LIBSSH2_FX_NOT_A_DIRECTORY 19UL
0216 #define LIBSSH2_FX_INVALID_FILENAME 20UL
0217 #define LIBSSH2_FX_LINK_LOOP 21UL
0218
0219
0220 #define LIBSSH2SFTP_EAGAIN LIBSSH2_ERROR_EAGAIN
0221
0222
0223 LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session);
0224 LIBSSH2_API int libssh2_sftp_shutdown(LIBSSH2_SFTP *sftp);
0225 LIBSSH2_API unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp);
0226 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_sftp_get_channel(LIBSSH2_SFTP *sftp);
0227
0228
0229 LIBSSH2_API LIBSSH2_SFTP_HANDLE *
0230 libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp,
0231 const char *filename,
0232 unsigned int filename_len,
0233 unsigned long flags,
0234 long mode, int open_type);
0235 #define libssh2_sftp_open(sftp, filename, flags, mode) \
0236 libssh2_sftp_open_ex((sftp), \
0237 (filename), (unsigned int)strlen(filename), \
0238 (flags), (mode), LIBSSH2_SFTP_OPENFILE)
0239 #define libssh2_sftp_opendir(sftp, path) \
0240 libssh2_sftp_open_ex((sftp), \
0241 (path), (unsigned int)strlen(path), \
0242 0, 0, LIBSSH2_SFTP_OPENDIR)
0243 LIBSSH2_API LIBSSH2_SFTP_HANDLE *
0244 libssh2_sftp_open_ex_r(LIBSSH2_SFTP *sftp,
0245 const char *filename,
0246 size_t filename_len,
0247 unsigned long flags,
0248 long mode, int open_type,
0249 LIBSSH2_SFTP_ATTRIBUTES *attrs);
0250 #define libssh2_sftp_open_r(sftp, filename, flags, mode, attrs) \
0251 libssh2_sftp_open_ex_r((sftp), (filename), strlen(filename), \
0252 (flags), (mode), LIBSSH2_SFTP_OPENFILE, \
0253 (attrs))
0254
0255 LIBSSH2_API ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle,
0256 char *buffer, size_t buffer_maxlen);
0257
0258 LIBSSH2_API int libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE *handle, \
0259 char *buffer, size_t buffer_maxlen,
0260 char *longentry,
0261 size_t longentry_maxlen,
0262 LIBSSH2_SFTP_ATTRIBUTES *attrs);
0263 #define libssh2_sftp_readdir(handle, buffer, buffer_maxlen, attrs) \
0264 libssh2_sftp_readdir_ex((handle), (buffer), (buffer_maxlen), NULL, 0, \
0265 (attrs))
0266
0267 LIBSSH2_API ssize_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
0268 const char *buffer, size_t count);
0269 LIBSSH2_API int libssh2_sftp_fsync(LIBSSH2_SFTP_HANDLE *handle);
0270
0271 LIBSSH2_API int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle);
0272 #define libssh2_sftp_close(handle) libssh2_sftp_close_handle(handle)
0273 #define libssh2_sftp_closedir(handle) libssh2_sftp_close_handle(handle)
0274
0275 LIBSSH2_API void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset);
0276 LIBSSH2_API void libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle,
0277 libssh2_uint64_t offset);
0278 #define libssh2_sftp_rewind(handle) libssh2_sftp_seek64((handle), 0)
0279
0280 LIBSSH2_API size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle);
0281 LIBSSH2_API libssh2_uint64_t libssh2_sftp_tell64(LIBSSH2_SFTP_HANDLE *handle);
0282
0283 LIBSSH2_API int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle,
0284 LIBSSH2_SFTP_ATTRIBUTES *attrs,
0285 int setstat);
0286 #define libssh2_sftp_fstat(handle, attrs) \
0287 libssh2_sftp_fstat_ex((handle), (attrs), 0)
0288 #define libssh2_sftp_fsetstat(handle, attrs) \
0289 libssh2_sftp_fstat_ex((handle), (attrs), 1)
0290
0291
0292 LIBSSH2_API int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp,
0293 const char *source_filename,
0294 unsigned int srouce_filename_len,
0295 const char *dest_filename,
0296 unsigned int dest_filename_len,
0297 long flags);
0298 #define libssh2_sftp_rename(sftp, sourcefile, destfile) \
0299 libssh2_sftp_rename_ex((sftp), \
0300 (sourcefile), (unsigned int)strlen(sourcefile), \
0301 (destfile), (unsigned int)strlen(destfile), \
0302 LIBSSH2_SFTP_RENAME_OVERWRITE | \
0303 LIBSSH2_SFTP_RENAME_ATOMIC | \
0304 LIBSSH2_SFTP_RENAME_NATIVE)
0305
0306 LIBSSH2_API int libssh2_sftp_posix_rename_ex(LIBSSH2_SFTP *sftp,
0307 const char *source_filename,
0308 size_t srouce_filename_len,
0309 const char *dest_filename,
0310 size_t dest_filename_len);
0311 #define libssh2_sftp_posix_rename(sftp, sourcefile, destfile) \
0312 libssh2_sftp_posix_rename_ex((sftp), (sourcefile), strlen(sourcefile), \
0313 (destfile), strlen(destfile))
0314
0315 LIBSSH2_API int libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp,
0316 const char *filename,
0317 unsigned int filename_len);
0318 #define libssh2_sftp_unlink(sftp, filename) \
0319 libssh2_sftp_unlink_ex((sftp), (filename), (unsigned int)strlen(filename))
0320
0321 LIBSSH2_API int libssh2_sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle,
0322 LIBSSH2_SFTP_STATVFS *st);
0323
0324 LIBSSH2_API int libssh2_sftp_statvfs(LIBSSH2_SFTP *sftp,
0325 const char *path,
0326 size_t path_len,
0327 LIBSSH2_SFTP_STATVFS *st);
0328
0329 LIBSSH2_API int libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp,
0330 const char *path,
0331 unsigned int path_len, long mode);
0332 #define libssh2_sftp_mkdir(sftp, path, mode) \
0333 libssh2_sftp_mkdir_ex((sftp), (path), (unsigned int)strlen(path), (mode))
0334
0335 LIBSSH2_API int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp,
0336 const char *path,
0337 unsigned int path_len);
0338 #define libssh2_sftp_rmdir(sftp, path) \
0339 libssh2_sftp_rmdir_ex((sftp), (path), (unsigned int)strlen(path))
0340
0341 LIBSSH2_API int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp,
0342 const char *path,
0343 unsigned int path_len,
0344 int stat_type,
0345 LIBSSH2_SFTP_ATTRIBUTES *attrs);
0346 #define libssh2_sftp_stat(sftp, path, attrs) \
0347 libssh2_sftp_stat_ex((sftp), (path), (unsigned int)strlen(path), \
0348 LIBSSH2_SFTP_STAT, (attrs))
0349 #define libssh2_sftp_lstat(sftp, path, attrs) \
0350 libssh2_sftp_stat_ex((sftp), (path), (unsigned int)strlen(path), \
0351 LIBSSH2_SFTP_LSTAT, (attrs))
0352 #define libssh2_sftp_setstat(sftp, path, attrs) \
0353 libssh2_sftp_stat_ex((sftp), (path), (unsigned int)strlen(path), \
0354 LIBSSH2_SFTP_SETSTAT, (attrs))
0355
0356 LIBSSH2_API int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp,
0357 const char *path,
0358 unsigned int path_len,
0359 char *target,
0360 unsigned int target_len,
0361 int link_type);
0362 #define libssh2_sftp_symlink(sftp, orig, linkpath) \
0363 libssh2_sftp_symlink_ex((sftp), \
0364 (orig), (unsigned int)strlen(orig), \
0365 (linkpath), (unsigned int)strlen(linkpath), \
0366 LIBSSH2_SFTP_SYMLINK)
0367 #define libssh2_sftp_readlink(sftp, path, target, maxlen) \
0368 libssh2_sftp_symlink_ex((sftp), \
0369 (path), (unsigned int)strlen(path), \
0370 (target), (maxlen), \
0371 LIBSSH2_SFTP_READLINK)
0372 #define libssh2_sftp_realpath(sftp, path, target, maxlen) \
0373 libssh2_sftp_symlink_ex((sftp), \
0374 (path), (unsigned int)strlen(path), \
0375 (target), (maxlen), \
0376 LIBSSH2_SFTP_REALPATH)
0377
0378 #ifdef __cplusplus
0379 }
0380 #endif
0381
0382 #endif