blob: 507d763ea510afc6349a82b192c7f731dee185ae [file] [log] [blame]
Adam Langleyd0592972015-03-30 14:49:51 -07001/* $OpenBSD: sftp-client.h,v 1.26 2015/01/14 13:54: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
24typedef struct SFTP_DIRENT SFTP_DIRENT;
25
26struct SFTP_DIRENT {
27 char *filename;
28 char *longname;
29 Attrib a;
30};
31
32/*
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 */
36struct 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/*
51 * Initialise a SSH filexfer connection. Returns NULL on error or
52 * a pointer to a initialized sftp_conn struct on success.
53 */
54struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
55
56u_int sftp_proto_version(struct sftp_conn *);
57
58/* Close file referred to by 'handle' */
Adam Langleyd0592972015-03-30 14:49:51 -070059int do_close(struct sftp_conn *, const u_char *, u_int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080060
61/* Read contents of 'path' to NULL-terminated array 'dir' */
Adam Langleyd0592972015-03-30 14:49:51 -070062int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080063
64/* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
65void free_sftp_dirents(SFTP_DIRENT **);
66
67/* Delete file 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070068int do_rm(struct sftp_conn *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080069
70/* Create directory 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070071int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080072
73/* Remove directory 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070074int do_rmdir(struct sftp_conn *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080075
76/* Get file attributes of 'path' (follows symlinks) */
Adam Langleyd0592972015-03-30 14:49:51 -070077Attrib *do_stat(struct sftp_conn *, const char *, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080078
79/* Get file attributes of 'path' (does not follow symlinks) */
Adam Langleyd0592972015-03-30 14:49:51 -070080Attrib *do_lstat(struct sftp_conn *, const char *, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080081
82/* Set file attributes of 'path' */
Adam Langleyd0592972015-03-30 14:49:51 -070083int do_setstat(struct sftp_conn *, const char *, Attrib *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080084
85/* Set file attributes of open file 'handle' */
Adam Langleyd0592972015-03-30 14:49:51 -070086int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080087
88/* Canonicalise 'path' - caller must free result */
Adam Langleyd0592972015-03-30 14:49:51 -070089char *do_realpath(struct sftp_conn *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080090
91/* Get statistics for filesystem hosting file at "path" */
92int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
93
94/* Rename 'oldpath' to 'newpath' */
Adam Langleyd0592972015-03-30 14:49:51 -070095int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080096
97/* Link 'oldpath' to 'newpath' */
Adam Langleyd0592972015-03-30 14:49:51 -070098int do_hardlink(struct sftp_conn *, const char *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -080099
100/* Rename 'oldpath' to 'newpath' */
Adam Langleyd0592972015-03-30 14:49:51 -0700101int do_symlink(struct sftp_conn *, const char *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800102
Adam Langleyd0592972015-03-30 14:49:51 -0700103/* Call fsync() on open file 'handle' */
104int do_fsync(struct sftp_conn *conn, u_char *, u_int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800105
106/*
107 * Download 'remote_path' to 'local_path'. Preserve permissions and times
108 * if 'pflag' is set
109 */
Adam Langleyd0592972015-03-30 14:49:51 -0700110int do_download(struct sftp_conn *, const char *, const char *,
111 Attrib *, int, int, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800112
113/*
114 * Recursively download 'remote_directory' to 'local_directory'. Preserve
115 * times if 'pflag' is set
116 */
Adam Langleyd0592972015-03-30 14:49:51 -0700117int download_dir(struct sftp_conn *, const char *, const char *,
118 Attrib *, int, int, int, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800119
120/*
121 * Upload 'local_path' to 'remote_path'. Preserve permissions and times
122 * if 'pflag' is set
123 */
Adam Langleyd0592972015-03-30 14:49:51 -0700124int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800125
126/*
127 * Recursively upload 'local_directory' to 'remote_directory'. Preserve
128 * times if 'pflag' is set
129 */
Adam Langleyd0592972015-03-30 14:49:51 -0700130int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
131 int);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800132
133/* Concatenate paths, taking care of slashes. Caller must free result. */
Adam Langleyd0592972015-03-30 14:49:51 -0700134char *path_append(const char *, const char *);
Greg Hartmanbd77cf72015-02-25 13:21:06 -0800135
136#endif