xref: /freebsd/crypto/openssh/sftp-client.h (revision edf85781)
1edf85781SEd Maste /* $OpenBSD: sftp-client.h,v 1.39 2023/09/08 05:56:13 djm Exp $ */
21e8db6e2SBrian Feldman 
31e8db6e2SBrian Feldman /*
4efcad6b7SDag-Erling Smørgrav  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
51e8db6e2SBrian Feldman  *
6efcad6b7SDag-Erling Smørgrav  * Permission to use, copy, modify, and distribute this software for any
7efcad6b7SDag-Erling Smørgrav  * purpose with or without fee is hereby granted, provided that the above
8efcad6b7SDag-Erling Smørgrav  * copyright notice and this permission notice appear in all copies.
91e8db6e2SBrian Feldman  *
10efcad6b7SDag-Erling Smørgrav  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11efcad6b7SDag-Erling Smørgrav  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12efcad6b7SDag-Erling Smørgrav  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13efcad6b7SDag-Erling Smørgrav  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14efcad6b7SDag-Erling Smørgrav  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15efcad6b7SDag-Erling Smørgrav  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16efcad6b7SDag-Erling Smørgrav  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
171e8db6e2SBrian Feldman  */
181e8db6e2SBrian Feldman 
191e8db6e2SBrian Feldman /* Client side of SSH2 filexfer protocol */
201e8db6e2SBrian Feldman 
21ae1f160dSDag-Erling Smørgrav #ifndef _SFTP_CLIENT_H
22ae1f160dSDag-Erling Smørgrav #define _SFTP_CLIENT_H
23ae1f160dSDag-Erling Smørgrav 
24acc1a9efSDag-Erling Smørgrav #ifdef USE_SYSTEM_GLOB
25acc1a9efSDag-Erling Smørgrav # include <glob.h>
26acc1a9efSDag-Erling Smørgrav #else
27acc1a9efSDag-Erling Smørgrav # include "openbsd-compat/glob.h"
28acc1a9efSDag-Erling Smørgrav #endif
29acc1a9efSDag-Erling Smørgrav 
301e8db6e2SBrian Feldman typedef struct SFTP_DIRENT SFTP_DIRENT;
311e8db6e2SBrian Feldman 
321e8db6e2SBrian Feldman struct SFTP_DIRENT {
331e8db6e2SBrian Feldman 	char *filename;
341e8db6e2SBrian Feldman 	char *longname;
351e8db6e2SBrian Feldman 	Attrib a;
361e8db6e2SBrian Feldman };
371e8db6e2SBrian Feldman 
381e8db6e2SBrian Feldman /*
39d4af9e69SDag-Erling Smørgrav  * Used for statvfs responses on the wire from the server, because the
40d4af9e69SDag-Erling Smørgrav  * server's native format may be larger than the client's.
41d4af9e69SDag-Erling Smørgrav  */
42d4af9e69SDag-Erling Smørgrav struct sftp_statvfs {
43d4af9e69SDag-Erling Smørgrav 	u_int64_t f_bsize;
44d4af9e69SDag-Erling Smørgrav 	u_int64_t f_frsize;
45d4af9e69SDag-Erling Smørgrav 	u_int64_t f_blocks;
46d4af9e69SDag-Erling Smørgrav 	u_int64_t f_bfree;
47d4af9e69SDag-Erling Smørgrav 	u_int64_t f_bavail;
48d4af9e69SDag-Erling Smørgrav 	u_int64_t f_files;
49d4af9e69SDag-Erling Smørgrav 	u_int64_t f_ffree;
50d4af9e69SDag-Erling Smørgrav 	u_int64_t f_favail;
51d4af9e69SDag-Erling Smørgrav 	u_int64_t f_fsid;
52d4af9e69SDag-Erling Smørgrav 	u_int64_t f_flag;
53d4af9e69SDag-Erling Smørgrav 	u_int64_t f_namemax;
54d4af9e69SDag-Erling Smørgrav };
55d4af9e69SDag-Erling Smørgrav 
5619261079SEd Maste /* Used for limits response on the wire from the server */
5719261079SEd Maste struct sftp_limits {
5819261079SEd Maste 	u_int64_t packet_length;
5919261079SEd Maste 	u_int64_t read_length;
6019261079SEd Maste 	u_int64_t write_length;
6119261079SEd Maste 	u_int64_t open_handles;
6219261079SEd Maste };
6319261079SEd Maste 
6419261079SEd Maste /* print flag values */
6519261079SEd Maste #define SFTP_QUIET		0	/* be quiet during transfers */
6619261079SEd Maste #define SFTP_PRINT		1	/* list files and show progress bar */
6719261079SEd Maste #define SFTP_PROGRESS_ONLY	2	/* progress bar only */
6819261079SEd Maste 
69d4af9e69SDag-Erling Smørgrav /*
70043840dfSDag-Erling Smørgrav  * Initialise a SSH filexfer connection. Returns NULL on error or
715e8dbd04SDag-Erling Smørgrav  * a pointer to a initialized sftp_conn struct on success.
721e8db6e2SBrian Feldman  */
73edf85781SEd Maste struct sftp_conn *sftp_init(int, int, u_int, u_int, u_int64_t);
74ae1f160dSDag-Erling Smørgrav 
75ee21a45fSDag-Erling Smørgrav u_int sftp_proto_version(struct sftp_conn *);
761e8db6e2SBrian Feldman 
7719261079SEd Maste /* Query server limits */
78edf85781SEd Maste int sftp_get_limits(struct sftp_conn *, struct sftp_limits *);
7919261079SEd Maste 
801e8db6e2SBrian Feldman /* Close file referred to by 'handle' */
81edf85781SEd Maste int sftp_close(struct sftp_conn *, const u_char *, u_int);
821e8db6e2SBrian Feldman 
831e8db6e2SBrian Feldman /* Read contents of 'path' to NULL-terminated array 'dir' */
84edf85781SEd Maste int sftp_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
851e8db6e2SBrian Feldman 
86edf85781SEd Maste /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from sftp_readdir) */
87edf85781SEd Maste void sftp_free_dirents(SFTP_DIRENT **);
881e8db6e2SBrian Feldman 
891e8db6e2SBrian Feldman /* Delete file 'path' */
90edf85781SEd Maste int sftp_rm(struct sftp_conn *, const char *);
911e8db6e2SBrian Feldman 
921e8db6e2SBrian Feldman /* Create directory 'path' */
93edf85781SEd Maste int sftp_mkdir(struct sftp_conn *, const char *, Attrib *, int);
941e8db6e2SBrian Feldman 
951e8db6e2SBrian Feldman /* Remove directory 'path' */
96edf85781SEd Maste int sftp_rmdir(struct sftp_conn *, const char *);
971e8db6e2SBrian Feldman 
981e8db6e2SBrian Feldman /* Get file attributes of 'path' (follows symlinks) */
99edf85781SEd Maste int sftp_stat(struct sftp_conn *, const char *, int, Attrib *);
1001e8db6e2SBrian Feldman 
1011e8db6e2SBrian Feldman /* Get file attributes of 'path' (does not follow symlinks) */
102edf85781SEd Maste int sftp_lstat(struct sftp_conn *, const char *, int, Attrib *);
1031e8db6e2SBrian Feldman 
1041e8db6e2SBrian Feldman /* Set file attributes of 'path' */
105edf85781SEd Maste int sftp_setstat(struct sftp_conn *, const char *, Attrib *);
1061e8db6e2SBrian Feldman 
1071e8db6e2SBrian Feldman /* Set file attributes of open file 'handle' */
108edf85781SEd Maste int sftp_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
1091e8db6e2SBrian Feldman 
11019261079SEd Maste /* Set file attributes of 'path', not following symlinks */
111edf85781SEd Maste int sftp_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a);
11219261079SEd Maste 
1131e8db6e2SBrian Feldman /* Canonicalise 'path' - caller must free result */
114edf85781SEd Maste char *sftp_realpath(struct sftp_conn *, const char *);
1151e8db6e2SBrian Feldman 
11619261079SEd Maste /* Canonicalisation with tilde expansion (requires server extension) */
117edf85781SEd Maste char *sftp_expand_path(struct sftp_conn *, const char *);
11819261079SEd Maste 
11919261079SEd Maste /* Returns non-zero if server can tilde-expand paths */
120edf85781SEd Maste int sftp_can_expand_path(struct sftp_conn *);
12119261079SEd Maste 
122d4af9e69SDag-Erling Smørgrav /* Get statistics for filesystem hosting file at "path" */
123edf85781SEd Maste int sftp_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
124d4af9e69SDag-Erling Smørgrav 
1251e8db6e2SBrian Feldman /* Rename 'oldpath' to 'newpath' */
126edf85781SEd Maste int sftp_rename(struct sftp_conn *, const char *, const char *, int);
1271e8db6e2SBrian Feldman 
12887c1498dSEd Maste /* Copy 'oldpath' to 'newpath' */
129edf85781SEd Maste int sftp_copy(struct sftp_conn *, const char *, const char *);
13087c1498dSEd Maste 
1314a421b63SDag-Erling Smørgrav /* Link 'oldpath' to 'newpath' */
132edf85781SEd Maste int sftp_hardlink(struct sftp_conn *, const char *, const char *);
1334a421b63SDag-Erling Smørgrav 
1341e8db6e2SBrian Feldman /* Rename 'oldpath' to 'newpath' */
135edf85781SEd Maste int sftp_symlink(struct sftp_conn *, const char *, const char *);
1361e8db6e2SBrian Feldman 
137f7167e0eSDag-Erling Smørgrav /* Call fsync() on open file 'handle' */
138edf85781SEd Maste int sftp_fsync(struct sftp_conn *conn, u_char *, u_int);
1391e8db6e2SBrian Feldman 
1401e8db6e2SBrian Feldman /*
1411e8db6e2SBrian Feldman  * Download 'remote_path' to 'local_path'. Preserve permissions and times
1421e8db6e2SBrian Feldman  * if 'pflag' is set
1431e8db6e2SBrian Feldman  */
144edf85781SEd Maste int sftp_download(struct sftp_conn *, const char *, const char *, Attrib *,
14538a52bd3SEd Maste     int, int, int, int);
146b15c8340SDag-Erling Smørgrav 
147b15c8340SDag-Erling Smørgrav /*
148b15c8340SDag-Erling Smørgrav  * Recursively download 'remote_directory' to 'local_directory'. Preserve
149b15c8340SDag-Erling Smørgrav  * times if 'pflag' is set
150b15c8340SDag-Erling Smørgrav  */
151edf85781SEd Maste int sftp_download_dir(struct sftp_conn *, const char *, const char *, Attrib *,
15238a52bd3SEd Maste     int, int, int, int, int, int);
1531e8db6e2SBrian Feldman 
1541e8db6e2SBrian Feldman /*
1551e8db6e2SBrian Feldman  * Upload 'local_path' to 'remote_path'. Preserve permissions and times
1561e8db6e2SBrian Feldman  * if 'pflag' is set
1571e8db6e2SBrian Feldman  */
158edf85781SEd Maste int sftp_upload(struct sftp_conn *, const char *, const char *,
15938a52bd3SEd Maste     int, int, int, int);
160ae1f160dSDag-Erling Smørgrav 
161b15c8340SDag-Erling Smørgrav /*
162b15c8340SDag-Erling Smørgrav  * Recursively upload 'local_directory' to 'remote_directory'. Preserve
163b15c8340SDag-Erling Smørgrav  * times if 'pflag' is set
164b15c8340SDag-Erling Smørgrav  */
165edf85781SEd Maste int sftp_upload_dir(struct sftp_conn *, const char *, const char *,
16638a52bd3SEd Maste     int, int, int, int, int, int);
16719261079SEd Maste 
16819261079SEd Maste /*
16919261079SEd Maste  * Download a 'from_path' from the 'from' connection and upload it to
17019261079SEd Maste  * to 'to' connection at 'to_path'.
17119261079SEd Maste  */
172edf85781SEd Maste int sftp_crossload(struct sftp_conn *from, struct sftp_conn *to,
17319261079SEd Maste     const char *from_path, const char *to_path,
17419261079SEd Maste     Attrib *a, int preserve_flag);
17519261079SEd Maste 
17619261079SEd Maste /*
17719261079SEd Maste  * Recursively download a directory from 'from_path' from the 'from'
17819261079SEd Maste  * connection and upload it to 'to' connection at 'to_path'.
17919261079SEd Maste  */
180edf85781SEd Maste int sftp_crossload_dir(struct sftp_conn *from, struct sftp_conn *to,
18119261079SEd Maste     const char *from_path, const char *to_path,
18219261079SEd Maste     Attrib *dirattrib, int preserve_flag, int print_flag,
18319261079SEd Maste     int follow_link_flag);
184b15c8340SDag-Erling Smørgrav 
18538a52bd3SEd Maste /*
18638a52bd3SEd Maste  * User/group ID to name translation.
18738a52bd3SEd Maste  */
188edf85781SEd Maste int sftp_can_get_users_groups_by_id(struct sftp_conn *conn);
189edf85781SEd Maste int sftp_get_users_groups_by_id(struct sftp_conn *conn,
19038a52bd3SEd Maste     const u_int *uids, u_int nuids,
19138a52bd3SEd Maste     const u_int *gids, u_int ngids,
19238a52bd3SEd Maste     char ***usernamesp, char ***groupnamesp);
19338a52bd3SEd Maste 
194b15c8340SDag-Erling Smørgrav /* Concatenate paths, taking care of slashes. Caller must free result. */
195edf85781SEd Maste char *sftp_path_append(const char *, const char *);
196b15c8340SDag-Erling Smørgrav 
19719261079SEd Maste /* Make absolute path if relative path and CWD is given. Does not modify
1981323ec57SEd Maste  * original if the path is already absolute. */
199edf85781SEd Maste char *sftp_make_absolute(char *, const char *);
20019261079SEd Maste 
20119261079SEd Maste /* Check if remote path is directory */
202edf85781SEd Maste int sftp_remote_is_dir(struct sftp_conn *conn, const char *path);
20319261079SEd Maste 
20419261079SEd Maste /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
205edf85781SEd Maste int sftp_globpath_is_dir(const char *pathname);
20619261079SEd Maste 
207ae1f160dSDag-Erling Smørgrav #endif
208