blob: 14a3b8182c490bb7799f56e22d0fc96f168dcb71 [file] [log] [blame]
djm@openbsd.orgc28a3432015-05-08 06:45:13 +00001/* $OpenBSD: sftp-client.h,v 1.27 2015/05/08 06:45:13 djm Exp $ */
Damien Miller33804262001-02-04 23:20:18 +11002
3/*
Damien Miller4e60ed72004-02-17 17:07:59 +11004 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
Damien Miller33804262001-02-04 23:20:18 +11005 *
Damien Miller4e60ed72004-02-17 17:07:59 +11006 * 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 Miller33804262001-02-04 23:20:18 +11009 *
Damien Miller4e60ed72004-02-17 17:07:59 +110010 * 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 Miller33804262001-02-04 23:20:18 +110017 */
18
19/* Client side of SSH2 filexfer protocol */
20
Damien Miller3db5f532002-02-13 14:10:32 +110021#ifndef _SFTP_CLIENT_H
22#define _SFTP_CLIENT_H
23
Darren Tucker8db134e2015-10-29 10:48:23 +110024#ifdef USE_SYSTEM_GLOB
25# include <glob.h>
26#else
27# include "openbsd-compat/glob.h"
28#endif
29
Damien Miller4870afd2001-03-14 10:27:09 +110030typedef struct SFTP_DIRENT SFTP_DIRENT;
31
32struct SFTP_DIRENT {
33 char *filename;
34 char *longname;
35 Attrib a;
36};
37
Ben Lindstroma3700052001-04-05 23:26:32 +000038/*
Darren Tucker7b598892008-06-09 22:49:36 +100039 * Used for statvfs responses on the wire from the server, because the
40 * server's native format may be larger than the client's.
41 */
42struct sftp_statvfs {
43 u_int64_t f_bsize;
44 u_int64_t f_frsize;
45 u_int64_t f_blocks;
46 u_int64_t f_bfree;
47 u_int64_t f_bavail;
48 u_int64_t f_files;
49 u_int64_t f_ffree;
50 u_int64_t f_favail;
51 u_int64_t f_fsid;
52 u_int64_t f_flag;
53 u_int64_t f_namemax;
54};
55
56/*
Damien Millerac7a0052005-05-26 12:05:49 +100057 * Initialise a SSH filexfer connection. Returns NULL on error or
Darren Tuckere2f189a2004-12-06 22:45:53 +110058 * a pointer to a initialized sftp_conn struct on success.
Damien Miller058316f2001-03-08 10:08:49 +110059 */
Damien Miller65e42f82010-09-24 22:15:11 +100060struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
Damien Miller3db5f532002-02-13 14:10:32 +110061
Ben Lindstromb1f483f2002-06-23 21:27:18 +000062u_int sftp_proto_version(struct sftp_conn *);
Damien Miller33804262001-02-04 23:20:18 +110063
64/* Close file referred to by 'handle' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000065int do_close(struct sftp_conn *, const u_char *, u_int);
Damien Miller33804262001-02-04 23:20:18 +110066
Damien Miller4870afd2001-03-14 10:27:09 +110067/* Read contents of 'path' to NULL-terminated array 'dir' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000068int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
Damien Miller4870afd2001-03-14 10:27:09 +110069
70/* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
Ben Lindstromb4c774c2001-07-04 04:07:12 +000071void free_sftp_dirents(SFTP_DIRENT **);
Damien Miller4870afd2001-03-14 10:27:09 +110072
Damien Miller33804262001-02-04 23:20:18 +110073/* Delete file 'path' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000074int do_rm(struct sftp_conn *, const char *);
Damien Miller33804262001-02-04 23:20:18 +110075
76/* Create directory 'path' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000077int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
Damien Miller33804262001-02-04 23:20:18 +110078
79/* Remove directory 'path' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000080int do_rmdir(struct sftp_conn *, const char *);
Damien Miller33804262001-02-04 23:20:18 +110081
82/* Get file attributes of 'path' (follows symlinks) */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000083Attrib *do_stat(struct sftp_conn *, const char *, int);
Damien Miller33804262001-02-04 23:20:18 +110084
85/* Get file attributes of 'path' (does not follow symlinks) */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000086Attrib *do_lstat(struct sftp_conn *, const char *, int);
Damien Miller33804262001-02-04 23:20:18 +110087
Damien Miller33804262001-02-04 23:20:18 +110088/* Set file attributes of 'path' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000089int do_setstat(struct sftp_conn *, const char *, Attrib *);
Damien Miller33804262001-02-04 23:20:18 +110090
91/* Set file attributes of open file 'handle' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000092int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
Damien Miller33804262001-02-04 23:20:18 +110093
94/* Canonicalise 'path' - caller must free result */
djm@openbsd.org7d845f42015-01-14 13:54:13 +000095char *do_realpath(struct sftp_conn *, const char *);
Damien Miller33804262001-02-04 23:20:18 +110096
Damien Millerd671e5a2008-05-19 14:53:33 +100097/* Get statistics for filesystem hosting file at "path" */
Darren Tucker7b598892008-06-09 22:49:36 +100098int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
Damien Millerd671e5a2008-05-19 14:53:33 +100099
Damien Miller33804262001-02-04 23:20:18 +1100100/* Rename 'oldpath' to 'newpath' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000101int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
Damien Miller33804262001-02-04 23:20:18 +1100102
Darren Tuckeraf1f9092010-12-05 09:02:47 +1100103/* Link 'oldpath' to 'newpath' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000104int do_hardlink(struct sftp_conn *, const char *, const char *);
Darren Tuckeraf1f9092010-12-05 09:02:47 +1100105
Damien Miller058316f2001-03-08 10:08:49 +1100106/* Rename 'oldpath' to 'newpath' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000107int do_symlink(struct sftp_conn *, const char *, const char *);
Damien Miller058316f2001-03-08 10:08:49 +1100108
Damien Millerf29238e2013-10-17 11:48:52 +1100109/* Call fsync() on open file 'handle' */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000110int do_fsync(struct sftp_conn *conn, u_char *, u_int);
Damien Millerf29238e2013-10-17 11:48:52 +1100111
Damien Miller33804262001-02-04 23:20:18 +1100112/*
113 * Download 'remote_path' to 'local_path'. Preserve permissions and times
114 * if 'pflag' is set
115 */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000116int do_download(struct sftp_conn *, const char *, const char *,
117 Attrib *, int, int, int);
Darren Tucker1b0dd172009-10-07 08:37:48 +1100118
119/*
djm@openbsd.orgc28a3432015-05-08 06:45:13 +0000120 * Recursively download 'remote_directory' to 'local_directory'. Preserve
Darren Tucker1b0dd172009-10-07 08:37:48 +1100121 * times if 'pflag' is set
122 */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000123int download_dir(struct sftp_conn *, const char *, const char *,
124 Attrib *, int, int, int, int);
Damien Miller33804262001-02-04 23:20:18 +1100125
126/*
127 * Upload 'local_path' to 'remote_path'. Preserve permissions and times
128 * if 'pflag' is set
129 */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000130int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
Damien Miller3db5f532002-02-13 14:10:32 +1100131
Darren Tucker1b0dd172009-10-07 08:37:48 +1100132/*
djm@openbsd.orgc28a3432015-05-08 06:45:13 +0000133 * Recursively upload 'local_directory' to 'remote_directory'. Preserve
Darren Tucker1b0dd172009-10-07 08:37:48 +1100134 * times if 'pflag' is set
135 */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000136int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
137 int);
Darren Tucker1b0dd172009-10-07 08:37:48 +1100138
139/* Concatenate paths, taking care of slashes. Caller must free result. */
djm@openbsd.org7d845f42015-01-14 13:54:13 +0000140char *path_append(const char *, const char *);
Darren Tucker1b0dd172009-10-07 08:37:48 +1100141
Damien Miller3db5f532002-02-13 14:10:32 +1100142#endif