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