1 /* $NetBSD: sftp-client.h,v 1.10 2017/04/18 18:41:46 christos Exp $ */ 2 /* $OpenBSD: sftp-client.h,v 1.27 2015/05/08 06:45:13 djm Exp $ */ 3 4 /* 5 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* Client side of SSH2 filexfer protocol */ 21 22 #ifndef _SFTP_CLIENT_H 23 #define _SFTP_CLIENT_H 24 25 typedef struct SFTP_DIRENT SFTP_DIRENT; 26 27 struct SFTP_DIRENT { 28 char *filename; 29 char *longname; 30 Attrib a; 31 }; 32 33 /* 34 * Used for statvfs responses on the wire from the server, because the 35 * server's native format may be larger than the client's. 36 */ 37 struct sftp_statvfs { 38 u_int64_t f_bsize; 39 u_int64_t f_frsize; 40 u_int64_t f_blocks; 41 u_int64_t f_bfree; 42 u_int64_t f_bavail; 43 u_int64_t f_files; 44 u_int64_t f_ffree; 45 u_int64_t f_favail; 46 u_int64_t f_fsid; 47 u_int64_t f_flag; 48 u_int64_t f_namemax; 49 }; 50 51 /* 52 * Initialise a SSH filexfer connection. Returns NULL on error or 53 * a pointer to a initialized sftp_conn struct on success. 54 */ 55 struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t); 56 57 u_int sftp_proto_version(struct sftp_conn *); 58 59 /* Close file referred to by 'handle' */ 60 int do_close(struct sftp_conn *, const u_char *, u_int); 61 62 /* Read contents of 'path' to NULL-terminated array 'dir' */ 63 int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***); 64 65 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */ 66 void free_sftp_dirents(SFTP_DIRENT **); 67 68 /* Delete file 'path' */ 69 int do_rm(struct sftp_conn *, const char *); 70 71 /* Create directory 'path' */ 72 int do_mkdir(struct sftp_conn *, const char *, Attrib *, int); 73 74 /* Remove directory 'path' */ 75 int do_rmdir(struct sftp_conn *, const char *); 76 77 /* Get file attributes of 'path' (follows symlinks) */ 78 Attrib *do_stat(struct sftp_conn *, const char *, int); 79 80 /* Get file attributes of 'path' (does not follow symlinks) */ 81 Attrib *do_lstat(struct sftp_conn *, const char *, int); 82 83 /* Set file attributes of 'path' */ 84 int do_setstat(struct sftp_conn *, const char *, Attrib *); 85 86 /* Set file attributes of open file 'handle' */ 87 int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *); 88 89 /* Canonicalise 'path' - caller must free result */ 90 char *do_realpath(struct sftp_conn *, const char *); 91 92 /* Get statistics for filesystem hosting file at "path" */ 93 int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int); 94 95 /* Rename 'oldpath' to 'newpath' */ 96 int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy); 97 98 /* Link 'oldpath' to 'newpath' */ 99 int do_hardlink(struct sftp_conn *, const char *, const char *); 100 101 /* Rename 'oldpath' to 'newpath' */ 102 int do_symlink(struct sftp_conn *, const char *, const char *); 103 104 /* Call fsync() on open file 'handle' */ 105 int do_fsync(struct sftp_conn *conn, u_char *, u_int); 106 107 /* 108 * Download 'remote_path' to 'local_path'. Preserve permissions and times 109 * if 'pflag' is set 110 */ 111 int do_download(struct sftp_conn *, const char *, const char *, 112 Attrib *, int, int, int); 113 114 /* 115 * Recursively download 'remote_directory' to 'local_directory'. Preserve 116 * times if 'pflag' is set 117 */ 118 int download_dir(struct sftp_conn *, const char *, const char *, 119 Attrib *, int, int, int, int); 120 121 /* 122 * Upload 'local_path' to 'remote_path'. Preserve permissions and times 123 * if 'pflag' is set 124 */ 125 int do_upload(struct sftp_conn *, const char *, const char *, int, int, int); 126 127 /* 128 * Recursively upload 'local_directory' to 'remote_directory'. Preserve 129 * times if 'pflag' is set 130 */ 131 int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int, 132 int); 133 134 /* Concatenate paths, taking care of slashes. Caller must free result. */ 135 char *path_append(const char *, const char *); 136 137 #endif 138