xref: /netbsd-src/crypto/external/bsd/openssh/dist/sftp-client.h (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /*	$NetBSD: sftp-client.h,v 1.3 2010/11/21 18:29:49 adam Exp $	*/
2 /* $OpenBSD: sftp-client.h,v 1.18 2009/08/18 18:36:20 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 /*
52  * Initialise a SSH filexfer connection. Returns NULL on error or
53  * a pointer to a initialized sftp_conn struct on success.
54  */
55 struct sftp_conn *do_init(int, int, u_int, u_int);
56 
57 u_int sftp_proto_version(struct sftp_conn *);
58 
59 /* Close file referred to by 'handle' */
60 int do_close(struct sftp_conn *, char *, u_int);
61 
62 /* Read contents of 'path' to NULL-terminated array 'dir' */
63 int do_readdir(struct sftp_conn *, char *, SFTP_DIRENT ***);
64 
65 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
66 void free_sftp_dirents(SFTP_DIRENT **);
67 
68 /* Delete file 'path' */
69 int do_rm(struct sftp_conn *, char *);
70 
71 /* Create directory 'path' */
72 int do_mkdir(struct sftp_conn *, char *, Attrib *, int);
73 
74 /* Remove directory 'path' */
75 int do_rmdir(struct sftp_conn *, char *);
76 
77 /* Get file attributes of 'path' (follows symlinks) */
78 Attrib *do_stat(struct sftp_conn *, char *, int);
79 
80 /* Get file attributes of 'path' (does not follow symlinks) */
81 Attrib *do_lstat(struct sftp_conn *, char *, int);
82 
83 /* Set file attributes of 'path' */
84 int do_setstat(struct sftp_conn *, char *, Attrib *);
85 
86 /* Set file attributes of open file 'handle' */
87 int do_fsetstat(struct sftp_conn *, char *, u_int, Attrib *);
88 
89 /* Canonicalise 'path' - caller must free result */
90 char *do_realpath(struct sftp_conn *, char *);
91 
92 /* Get statistics for filesystem hosting file at "path" */
93 int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
94 
95 /* Rename 'oldpath' to 'newpath' */
96 int do_rename(struct sftp_conn *, char *, char *);
97 
98 /* Rename 'oldpath' to 'newpath' */
99 int do_symlink(struct sftp_conn *, char *, char *);
100 
101 /* XXX: add callbacks to do_download/do_upload so we can do progress meter */
102 
103 /*
104  * Download 'remote_path' to 'local_path'. Preserve permissions and times
105  * if 'pflag' is set
106  */
107 int do_download(struct sftp_conn *, char *, char *, Attrib *, int);
108 
109 /*
110  * Recursively download 'remote_directory' to 'local_directory'. Preserve
111  * times if 'pflag' is set
112  */
113 int download_dir(struct sftp_conn *, char *, char *, Attrib *, int, int);
114 
115 /*
116  * Upload 'local_path' to 'remote_path'. Preserve permissions and times
117  * if 'pflag' is set
118  */
119 int do_upload(struct sftp_conn *, char *, char *, int);
120 
121 /*
122  * Recursively upload 'local_directory' to 'remote_directory'. Preserve
123  * times if 'pflag' is set
124  */
125 int upload_dir(struct sftp_conn *, char *, char *, int, int);
126 
127 /* Concatenate paths, taking care of slashes. Caller must free result. */
128 char *path_append(char *, char *);
129 
130 #endif
131