• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* $OpenBSD: sftp-client.h,v 1.27 2015/05/08 06:45:13 djm Exp $ */
2 
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 
24 #ifdef USE_SYSTEM_GLOB
25 # include <glob.h>
26 #else
27 # include "openbsd-compat/glob.h"
28 #endif
29 
30 typedef struct SFTP_DIRENT SFTP_DIRENT;
31 
32 struct 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  */
42 struct 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  */
60 struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
61 
62 u_int sftp_proto_version(struct sftp_conn *);
63 
64 /* Close file referred to by 'handle' */
65 int do_close(struct sftp_conn *, const u_char *, u_int);
66 
67 /* Read contents of 'path' to NULL-terminated array 'dir' */
68 int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
69 
70 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
71 void free_sftp_dirents(SFTP_DIRENT **);
72 
73 /* Delete file 'path' */
74 int do_rm(struct sftp_conn *, const char *);
75 
76 /* Create directory 'path' */
77 int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
78 
79 /* Remove directory 'path' */
80 int do_rmdir(struct sftp_conn *, const char *);
81 
82 /* Get file attributes of 'path' (follows symlinks) */
83 Attrib *do_stat(struct sftp_conn *, const char *, int);
84 
85 /* Get file attributes of 'path' (does not follow symlinks) */
86 Attrib *do_lstat(struct sftp_conn *, const char *, int);
87 
88 /* Set file attributes of 'path' */
89 int do_setstat(struct sftp_conn *, const char *, Attrib *);
90 
91 /* Set file attributes of open file 'handle' */
92 int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
93 
94 /* Canonicalise 'path' - caller must free result */
95 char *do_realpath(struct sftp_conn *, const char *);
96 
97 /* Get statistics for filesystem hosting file at "path" */
98 int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
99 
100 /* Rename 'oldpath' to 'newpath' */
101 int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
102 
103 /* Link 'oldpath' to 'newpath' */
104 int do_hardlink(struct sftp_conn *, const char *, const char *);
105 
106 /* Rename 'oldpath' to 'newpath' */
107 int do_symlink(struct sftp_conn *, const char *, const char *);
108 
109 /* Call fsync() on open file 'handle' */
110 int do_fsync(struct sftp_conn *conn, u_char *, u_int);
111 
112 /*
113  * Download 'remote_path' to 'local_path'. Preserve permissions and times
114  * if 'pflag' is set
115  */
116 int do_download(struct sftp_conn *, const char *, const char *,
117     Attrib *, int, int, int);
118 
119 /*
120  * Recursively download 'remote_directory' to 'local_directory'. Preserve
121  * times if 'pflag' is set
122  */
123 int download_dir(struct sftp_conn *, const char *, const char *,
124     Attrib *, int, int, int, int);
125 
126 /*
127  * Upload 'local_path' to 'remote_path'. Preserve permissions and times
128  * if 'pflag' is set
129  */
130 int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
131 
132 /*
133  * Recursively upload 'local_directory' to 'remote_directory'. Preserve
134  * times if 'pflag' is set
135  */
136 int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
137     int);
138 
139 /* Concatenate paths, taking care of slashes. Caller must free result. */
140 char *path_append(const char *, const char *);
141 
142 #endif
143