blob: 14a3b8182c490bb7799f56e22d0fc96f168dcb71 [file] [log] [blame]
Greg Hartmanccacbc92016-02-03 09:59:44 -08001/* $OpenBSD: sftp-client.h,v 1.27 2015/05/08 06:45:13 djm Exp $ */
Greg Hartmanbd77cf72015-02-25 13:21:06 -08002
3/*
4 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
5 *
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.
9 *
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.
17 */
18
19/* Client side of SSH2 filexfer protocol */
20
21#ifndef _SFTP_CLIENT_H
22#define _SFTP_CLIENT_H
23
Greg Hartman9768ca42017-06-22 20:49:52 -070024#ifdef USE_SYSTEM_GLOB
25# include <glob.h>
26#else
27# include "openbsd-compat/glob.h"
28#endif
29
Greg Hartmanbd77cf72015-02-25 13:21:06 -080030typedef struct SFTP_DIRENT SFTP_DIRENT;
31
32struct SFTP_DIRENT {
33 char *filename;
34 char *longname;
35 Attrib a;
36};
37
38/*
39 * 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/*
57 * Initialise a SSH filexfer connection. Returns NULL on error or
58 * a pointer to a initialized sftp_conn struct on success.
59 */
60struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
61
62u_int sftp_proto_version(struct sftp_conn *);
63
64/* Close file referred to by 'handle' */
Adam Langleyd0592972015-03-30 14:49:51 -070065int do_close(struct sftp_conn *, const u_char *, u_int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080066
67/* Read contents of 'path' to NULL-terminated array 'dir' */
Adam Langleyd0592972015-03-30 14:49:51 -070068int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080069
70/* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
71void free_sftp_dirents(SFTP_DIRENT **);
72
73/* Delete file 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070074int do_rm(struct sftp_conn *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080075
76/* Create directory 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070077int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080078
79/* Remove directory 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070080int do_rmdir(struct sftp_conn *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080081
82/* Get file attributes of 'path' (follows symlinks) */
Adam Langleyd0592972015-03-30 14:49:51 -070083Attrib *do_stat(struct sftp_conn *, const char *, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080084
85/* Get file attributes of 'path' (does not follow symlinks) */
Adam Langleyd0592972015-03-30 14:49:51 -070086Attrib *do_lstat(struct sftp_conn *, const char *, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080087
88/* Set file attributes of 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070089int do_setstat(struct sftp_conn *, const char *, Attrib *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080090
91/* Set file attributes of open file 'handle' */
Adam Langleyd0592972015-03-30 14:49:51 -070092int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080093
94/* Canonicalise 'path' - caller must free result */
Adam Langleyd0592972015-03-30 14:49:51 -070095char *do_realpath(struct sftp_conn *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080096
97/* Get statistics for filesystem hosting file at "path" */
98int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
99
100/* Rename 'oldpath' to 'newpath' */
Adam Langleyd0592972015-03-30 14:49:51 -0700101int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800102
103/* Link 'oldpath' to 'newpath' */
Adam Langleyd0592972015-03-30 14:49:51 -0700104int do_hardlink(struct sftp_conn *, const char *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800105
106/* Rename 'oldpath' to 'newpath' */
Adam Langleyd0592972015-03-30 14:49:51 -0700107int do_symlink(struct sftp_conn *, const char *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800108
Adam Langleyd0592972015-03-30 14:49:51 -0700109/* Call fsync() on open file 'handle' */
110int do_fsync(struct sftp_conn *conn, u_char *, u_int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800111
112/*
113 * Download 'remote_path' to 'local_path'. Preserve permissions and times
114 * if 'pflag' is set
115 */
Adam Langleyd0592972015-03-30 14:49:51 -0700116int do_download(struct sftp_conn *, const char *, const char *,
117 Attrib *, int, int, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800118
119/*
Greg Hartmanccacbc92016-02-03 09:59:44 -0800120 * Recursively download 'remote_directory' to 'local_directory'. Preserve
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800121 * times if 'pflag' is set
122 */
Adam Langleyd0592972015-03-30 14:49:51 -0700123int download_dir(struct sftp_conn *, const char *, const char *,
124 Attrib *, int, int, int, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800125
126/*
127 * Upload 'local_path' to 'remote_path'. Preserve permissions and times
128 * if 'pflag' is set
129 */
Adam Langleyd0592972015-03-30 14:49:51 -0700130int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800131
132/*
Greg Hartmanccacbc92016-02-03 09:59:44 -0800133 * Recursively upload 'local_directory' to 'remote_directory'. Preserve
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800134 * times if 'pflag' is set
135 */
Adam Langleyd0592972015-03-30 14:49:51 -0700136int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
137 int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800138
139/* Concatenate paths, taking care of slashes. Caller must free result. */
Adam Langleyd0592972015-03-30 14:49:51 -0700140char *path_append(const char *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800141
142#endif