1 /* $NetBSD: sftp-client.h,v 1.13 2021/04/19 14:40:15 christos Exp $ */ 2 /* $OpenBSD: sftp-client.h,v 1.30 2021/03/31 22:16:34 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 /* Used for limits response on the wire from the server */ 52 struct sftp_limits { 53 u_int64_t packet_length; 54 u_int64_t read_length; 55 u_int64_t write_length; 56 u_int64_t open_handles; 57 }; 58 59 /* 60 * Initialise a SSH filexfer connection. Returns NULL on error or 61 * a pointer to a initialized sftp_conn struct on success. 62 */ 63 struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t); 64 65 u_int sftp_proto_version(struct sftp_conn *); 66 67 /* Query server limits */ 68 int do_limits(struct sftp_conn *, struct sftp_limits *); 69 70 /* Close file referred to by 'handle' */ 71 int do_close(struct sftp_conn *, const u_char *, u_int); 72 73 /* Read contents of 'path' to NULL-terminated array 'dir' */ 74 int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***); 75 76 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */ 77 void free_sftp_dirents(SFTP_DIRENT **); 78 79 /* Delete file 'path' */ 80 int do_rm(struct sftp_conn *, const char *); 81 82 /* Create directory 'path' */ 83 int do_mkdir(struct sftp_conn *, const char *, Attrib *, int); 84 85 /* Remove directory 'path' */ 86 int do_rmdir(struct sftp_conn *, const char *); 87 88 /* Get file attributes of 'path' (follows symlinks) */ 89 Attrib *do_stat(struct sftp_conn *, const char *, int); 90 91 /* Get file attributes of 'path' (does not follow symlinks) */ 92 Attrib *do_lstat(struct sftp_conn *, const char *, int); 93 94 /* Set file attributes of 'path' */ 95 int do_setstat(struct sftp_conn *, const char *, Attrib *); 96 97 /* Set file attributes of open file 'handle' */ 98 int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *); 99 100 /* Set file attributes of 'path', not following symlinks */ 101 int do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a); 102 103 /* Canonicalise 'path' - caller must free result */ 104 char *do_realpath(struct sftp_conn *, const char *); 105 106 /* Get statistics for filesystem hosting file at "path" */ 107 int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int); 108 109 /* Rename 'oldpath' to 'newpath' */ 110 int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy); 111 112 /* Link 'oldpath' to 'newpath' */ 113 int do_hardlink(struct sftp_conn *, const char *, const char *); 114 115 /* Rename 'oldpath' to 'newpath' */ 116 int do_symlink(struct sftp_conn *, const char *, const char *); 117 118 /* Call fsync() on open file 'handle' */ 119 int do_fsync(struct sftp_conn *conn, u_char *, u_int); 120 121 /* 122 * Download 'remote_path' to 'local_path'. Preserve permissions and times 123 * if 'pflag' is set 124 */ 125 int do_download(struct sftp_conn *, const char *, const char *, 126 Attrib *, int, int, int); 127 128 /* 129 * Recursively download 'remote_directory' to 'local_directory'. Preserve 130 * times if 'pflag' is set 131 */ 132 int download_dir(struct sftp_conn *, const char *, const char *, 133 Attrib *, int, int, int, int); 134 135 /* 136 * Upload 'local_path' to 'remote_path'. Preserve permissions and times 137 * if 'pflag' is set 138 */ 139 int do_upload(struct sftp_conn *, const char *, const char *, int, int, int); 140 141 /* 142 * Recursively upload 'local_directory' to 'remote_directory'. Preserve 143 * times if 'pflag' is set 144 */ 145 int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int, 146 int); 147 148 /* Concatenate paths, taking care of slashes. Caller must free result. */ 149 char *path_append(const char *, const char *); 150 151 /* Make absolute path if relative path and CWD is given. Does not modify 152 * original if the the path is already absolute. */ 153 char *make_absolute(char *, const char *); 154 155 /* Check if remote path is directory */ 156 int remote_is_dir(struct sftp_conn *conn, const char *path); 157 158 /* Check if local path is directory */ 159 int local_is_dir(const char *path); 160 161 /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */ 162 int globpath_is_dir(const char *pathname); 163 164 #endif 165