1 /* $OpenBSD: sftp-client.h,v 1.38 2022/09/19 10:43:12 djm Exp $ */
4 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
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.
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.
19 /* Client side of SSH2 filexfer protocol */
21 #ifndef _SFTP_CLIENT_H
22 #define _SFTP_CLIENT_H
24 #ifdef USE_SYSTEM_GLOB
27 # include "openbsd-compat/glob.h"
30 typedef struct SFTP_DIRENT SFTP_DIRENT
;
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.
56 /* Used for limits response on the wire from the server */
58 u_int64_t packet_length
;
59 u_int64_t read_length
;
60 u_int64_t write_length
;
61 u_int64_t open_handles
;
64 /* print flag values */
65 #define SFTP_QUIET 0 /* be quiet during transfers */
66 #define SFTP_PRINT 1 /* list files and show progress bar */
67 #define SFTP_PROGRESS_ONLY 2 /* progress bar only */
70 * Initialise a SSH filexfer connection. Returns NULL on error or
71 * a pointer to a initialized sftp_conn struct on success.
73 struct sftp_conn
*do_init(int, int, u_int
, u_int
, u_int64_t
);
75 u_int
sftp_proto_version(struct sftp_conn
*);
77 /* Query server limits */
78 int do_limits(struct sftp_conn
*, struct sftp_limits
*);
80 /* Close file referred to by 'handle' */
81 int do_close(struct sftp_conn
*, const u_char
*, u_int
);
83 /* Read contents of 'path' to NULL-terminated array 'dir' */
84 int do_readdir(struct sftp_conn
*, const char *, SFTP_DIRENT
***);
86 /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
87 void free_sftp_dirents(SFTP_DIRENT
**);
89 /* Delete file 'path' */
90 int do_rm(struct sftp_conn
*, const char *);
92 /* Create directory 'path' */
93 int do_mkdir(struct sftp_conn
*, const char *, Attrib
*, int);
95 /* Remove directory 'path' */
96 int do_rmdir(struct sftp_conn
*, const char *);
98 /* Get file attributes of 'path' (follows symlinks) */
99 Attrib
*do_stat(struct sftp_conn
*, const char *, int);
101 /* Get file attributes of 'path' (does not follow symlinks) */
102 Attrib
*do_lstat(struct sftp_conn
*, const char *, int);
104 /* Set file attributes of 'path' */
105 int do_setstat(struct sftp_conn
*, const char *, Attrib
*);
107 /* Set file attributes of open file 'handle' */
108 int do_fsetstat(struct sftp_conn
*, const u_char
*, u_int
, Attrib
*);
110 /* Set file attributes of 'path', not following symlinks */
111 int do_lsetstat(struct sftp_conn
*conn
, const char *path
, Attrib
*a
);
113 /* Canonicalise 'path' - caller must free result */
114 char *do_realpath(struct sftp_conn
*, const char *);
116 /* Canonicalisation with tilde expansion (requires server extension) */
117 char *do_expand_path(struct sftp_conn
*, const char *);
119 /* Returns non-zero if server can tilde-expand paths */
120 int can_expand_path(struct sftp_conn
*);
122 /* Get statistics for filesystem hosting file at "path" */
123 int do_statvfs(struct sftp_conn
*, const char *, struct sftp_statvfs
*, int);
125 /* Rename 'oldpath' to 'newpath' */
126 int do_rename(struct sftp_conn
*, const char *, const char *, int);
128 /* Copy 'oldpath' to 'newpath' */
129 int do_copy(struct sftp_conn
*, const char *, const char *);
131 /* Link 'oldpath' to 'newpath' */
132 int do_hardlink(struct sftp_conn
*, const char *, const char *);
134 /* Rename 'oldpath' to 'newpath' */
135 int do_symlink(struct sftp_conn
*, const char *, const char *);
137 /* Call fsync() on open file 'handle' */
138 int do_fsync(struct sftp_conn
*conn
, u_char
*, u_int
);
141 * Download 'remote_path' to 'local_path'. Preserve permissions and times
144 int do_download(struct sftp_conn
*, const char *, const char *, Attrib
*,
148 * Recursively download 'remote_directory' to 'local_directory'. Preserve
149 * times if 'pflag' is set
151 int download_dir(struct sftp_conn
*, const char *, const char *, Attrib
*,
152 int, int, int, int, int, int);
155 * Upload 'local_path' to 'remote_path'. Preserve permissions and times
158 int do_upload(struct sftp_conn
*, const char *, const char *,
162 * Recursively upload 'local_directory' to 'remote_directory'. Preserve
163 * times if 'pflag' is set
165 int upload_dir(struct sftp_conn
*, const char *, const char *,
166 int, int, int, int, int, int);
169 * Download a 'from_path' from the 'from' connection and upload it to
170 * to 'to' connection at 'to_path'.
173 do_crossload(struct sftp_conn
*from
, struct sftp_conn
*to
,
174 const char *from_path
, const char *to_path
,
175 Attrib
*a
, int preserve_flag
);
178 * Recursively download a directory from 'from_path' from the 'from'
179 * connection and upload it to 'to' connection at 'to_path'.
181 int crossload_dir(struct sftp_conn
*from
, struct sftp_conn
*to
,
182 const char *from_path
, const char *to_path
,
183 Attrib
*dirattrib
, int preserve_flag
, int print_flag
,
184 int follow_link_flag
);
187 * User/group ID to name translation.
189 int can_get_users_groups_by_id(struct sftp_conn
*conn
);
190 int do_get_users_groups_by_id(struct sftp_conn
*conn
,
191 const u_int
*uids
, u_int nuids
,
192 const u_int
*gids
, u_int ngids
,
193 char ***usernamesp
, char ***groupnamesp
);
195 /* Concatenate paths, taking care of slashes. Caller must free result. */
196 char *path_append(const char *, const char *);
198 /* Make absolute path if relative path and CWD is given. Does not modify
199 * original if the path is already absolute. */
200 char *make_absolute(char *, const char *);
202 /* Check if remote path is directory */
203 int remote_is_dir(struct sftp_conn
*conn
, const char *path
);
205 /* Check if local path is directory */
206 int local_is_dir(const char *path
);
208 /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
209 int globpath_is_dir(const char *pathname
);