Grid Community Toolkit  6.2.1629922860 (tag: v6.2.20210826)
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sftp-client.h
1 /* $OpenBSD: sftp-client.h,v 1.30 2021/03/31 22:16:34 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 /* Used for limits response on the wire from the server */
57 struct sftp_limits {
58  u_int64_t packet_length;
59  u_int64_t read_length;
60  u_int64_t write_length;
61  u_int64_t open_handles;
62 };
63 
64 /*
65  * Initialise a SSH filexfer connection. Returns NULL on error or
66  * a pointer to a initialized sftp_conn struct on success.
67  */
68 struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
69 
70 u_int sftp_proto_version(struct sftp_conn *);
71 
72 /* Query server limits */
73 int do_limits(struct sftp_conn *, struct sftp_limits *);
74 
75 /* Close file referred to by 'handle' */
76 int do_close(struct sftp_conn *, const u_char *, u_int);
77 
78 /* Read contents of 'path' to NULL-terminated array 'dir' */
79 int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
80 
81 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
82 void free_sftp_dirents(SFTP_DIRENT **);
83 
84 /* Delete file 'path' */
85 int do_rm(struct sftp_conn *, const char *);
86 
87 /* Create directory 'path' */
88 int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
89 
90 /* Remove directory 'path' */
91 int do_rmdir(struct sftp_conn *, const char *);
92 
93 /* Get file attributes of 'path' (follows symlinks) */
94 Attrib *do_stat(struct sftp_conn *, const char *, int);
95 
96 /* Get file attributes of 'path' (does not follow symlinks) */
97 Attrib *do_lstat(struct sftp_conn *, const char *, int);
98 
99 /* Set file attributes of 'path' */
100 int do_setstat(struct sftp_conn *, const char *, Attrib *);
101 
102 /* Set file attributes of open file 'handle' */
103 int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
104 
105 /* Set file attributes of 'path', not following symlinks */
106 int do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a);
107 
108 /* Canonicalise 'path' - caller must free result */
109 char *do_realpath(struct sftp_conn *, const char *);
110 
111 /* Get statistics for filesystem hosting file at "path" */
112 int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
113 
114 /* Rename 'oldpath' to 'newpath' */
115 int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
116 
117 /* Link 'oldpath' to 'newpath' */
118 int do_hardlink(struct sftp_conn *, const char *, const char *);
119 
120 /* Rename 'oldpath' to 'newpath' */
121 int do_symlink(struct sftp_conn *, const char *, const char *);
122 
123 /* Call fsync() on open file 'handle' */
124 int do_fsync(struct sftp_conn *conn, u_char *, u_int);
125 
126 /*
127  * Download 'remote_path' to 'local_path'. Preserve permissions and times
128  * if 'pflag' is set
129  */
130 int do_download(struct sftp_conn *, const char *, const char *,
131  Attrib *, int, int, int);
132 
133 /*
134  * Recursively download 'remote_directory' to 'local_directory'. Preserve
135  * times if 'pflag' is set
136  */
137 int download_dir(struct sftp_conn *, const char *, const char *,
138  Attrib *, int, int, int, int);
139 
140 /*
141  * Upload 'local_path' to 'remote_path'. Preserve permissions and times
142  * if 'pflag' is set
143  */
144 int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
145 
146 /*
147  * Recursively upload 'local_directory' to 'remote_directory'. Preserve
148  * times if 'pflag' is set
149  */
150 int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
151  int);
152 
153 /* Concatenate paths, taking care of slashes. Caller must free result. */
154 char *path_append(const char *, const char *);
155 
156 /* Make absolute path if relative path and CWD is given. Does not modify
157  * original if the the path is already absolute. */
158 char *make_absolute(char *, const char *);
159 
160 /* Check if remote path is directory */
161 int remote_is_dir(struct sftp_conn *conn, const char *path);
162 
163 /* Check if local path is directory */
164 int local_is_dir(const char *path);
165 
166 /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
167 int globpath_is_dir(const char *pathname);
168 
169 #endif