[BACK]Return to sftp-client.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/sftp-client.h, Revision 1.39

1.39    ! djm         1: /* $OpenBSD: sftp-client.h,v 1.38 2022/09/19 10:43:12 djm Exp $ */
1.1       djm         2:
                      3: /*
1.12      djm         4:  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
1.1       djm         5:  *
1.12      djm         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.
1.1       djm         9:  *
1.12      djm        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.
1.1       djm        17:  */
                     18:
                     19: /* Client side of SSH2 filexfer protocol */
                     20:
1.9       djm        21: #ifndef _SFTP_CLIENT_H
                     22: #define _SFTP_CLIENT_H
                     23:
1.3       djm        24: typedef struct SFTP_DIRENT SFTP_DIRENT;
                     25:
                     26: struct SFTP_DIRENT {
                     27:        char *filename;
                     28:        char *longname;
                     29:        Attrib a;
                     30: };
                     31:
1.5       markus     32: /*
1.17      dtucker    33:  * Used for statvfs responses on the wire from the server, because the
                     34:  * server's native format may be larger than the client's.
                     35:  */
                     36: struct sftp_statvfs {
                     37:        u_int64_t f_bsize;
                     38:        u_int64_t f_frsize;
                     39:        u_int64_t f_blocks;
                     40:        u_int64_t f_bfree;
                     41:        u_int64_t f_bavail;
                     42:        u_int64_t f_files;
                     43:        u_int64_t f_ffree;
                     44:        u_int64_t f_favail;
                     45:        u_int64_t f_fsid;
                     46:        u_int64_t f_flag;
                     47:        u_int64_t f_namemax;
                     48: };
                     49:
1.30      djm        50: /* Used for limits response on the wire from the server */
                     51: struct sftp_limits {
                     52:        u_int64_t packet_length;
                     53:        u_int64_t read_length;
                     54:        u_int64_t write_length;
                     55:        u_int64_t open_handles;
                     56: };
1.32      djm        57:
                     58: /* print flag values */
                     59: #define SFTP_QUIET             0       /* be quiet during transfers */
                     60: #define SFTP_PRINT             1       /* list files and show progress bar */
                     61: #define SFTP_PROGRESS_ONLY     2       /* progress bar only */
1.30      djm        62:
1.17      dtucker    63: /*
1.14      jmc        64:  * Initialise a SSH filexfer connection. Returns NULL on error or
1.13      djm        65:  * a pointer to a initialized sftp_conn struct on success.
1.2       djm        66:  */
1.39    ! djm        67: struct sftp_conn *sftp_init(int, int, u_int, u_int, u_int64_t);
1.9       djm        68:
1.10      deraadt    69: u_int sftp_proto_version(struct sftp_conn *);
1.30      djm        70:
                     71: /* Query server limits */
1.39    ! djm        72: int sftp_get_limits(struct sftp_conn *, struct sftp_limits *);
1.1       djm        73:
                     74: /* Close file referred to by 'handle' */
1.39    ! djm        75: int sftp_close(struct sftp_conn *, const u_char *, u_int);
1.3       djm        76:
                     77: /* Read contents of 'path' to NULL-terminated array 'dir' */
1.39    ! djm        78: int sftp_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
1.3       djm        79:
1.39    ! djm        80: /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from sftp_readdir) */
        !            81: void sftp_free_dirents(SFTP_DIRENT **);
1.1       djm        82:
                     83: /* Delete file 'path' */
1.39    ! djm        84: int sftp_rm(struct sftp_conn *, const char *);
1.1       djm        85:
                     86: /* Create directory 'path' */
1.39    ! djm        87: int sftp_mkdir(struct sftp_conn *, const char *, Attrib *, int);
1.1       djm        88:
                     89: /* Remove directory 'path' */
1.39    ! djm        90: int sftp_rmdir(struct sftp_conn *, const char *);
1.1       djm        91:
                     92: /* Get file attributes of 'path' (follows symlinks) */
1.39    ! djm        93: int sftp_stat(struct sftp_conn *, const char *, int, Attrib *);
1.1       djm        94:
                     95: /* Get file attributes of 'path' (does not follow symlinks) */
1.39    ! djm        96: int sftp_lstat(struct sftp_conn *, const char *, int, Attrib *);
1.1       djm        97:
                     98: /* Set file attributes of 'path' */
1.39    ! djm        99: int sftp_setstat(struct sftp_conn *, const char *, Attrib *);
1.1       djm       100:
                    101: /* Set file attributes of open file 'handle' */
1.39    ! djm       102: int sftp_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
1.28      djm       103:
                    104: /* Set file attributes of 'path', not following symlinks */
1.39    ! djm       105: int sftp_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a);
1.1       djm       106:
                    107: /* Canonicalise 'path' - caller must free result */
1.39    ! djm       108: char *sftp_realpath(struct sftp_conn *, const char *);
1.16      djm       109:
1.34      djm       110: /* Canonicalisation with tilde expansion (requires server extension) */
1.39    ! djm       111: char *sftp_expand_path(struct sftp_conn *, const char *);
1.34      djm       112:
                    113: /* Returns non-zero if server can tilde-expand paths */
1.39    ! djm       114: int sftp_can_expand_path(struct sftp_conn *);
1.34      djm       115:
1.16      djm       116: /* Get statistics for filesystem hosting file at "path" */
1.39    ! djm       117: int sftp_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
1.1       djm       118:
                    119: /* Rename 'oldpath' to 'newpath' */
1.39    ! djm       120: int sftp_rename(struct sftp_conn *, const char *, const char *, int);
1.36      djm       121:
                    122: /* Copy 'oldpath' to 'newpath' */
1.39    ! djm       123: int sftp_copy(struct sftp_conn *, const char *, const char *);
1.20      djm       124:
                    125: /* Link 'oldpath' to 'newpath' */
1.39    ! djm       126: int sftp_hardlink(struct sftp_conn *, const char *, const char *);
1.2       djm       127:
                    128: /* Rename 'oldpath' to 'newpath' */
1.39    ! djm       129: int sftp_symlink(struct sftp_conn *, const char *, const char *);
1.1       djm       130:
1.24      djm       131: /* Call fsync() on open file 'handle' */
1.39    ! djm       132: int sftp_fsync(struct sftp_conn *conn, u_char *, u_int);
1.24      djm       133:
1.1       djm       134: /*
                    135:  * Download 'remote_path' to 'local_path'. Preserve permissions and times
                    136:  * if 'pflag' is set
                    137:  */
1.39    ! djm       138: int sftp_download(struct sftp_conn *, const char *, const char *, Attrib *,
1.37      djm       139:     int, int, int, int);
1.18      djm       140:
                    141: /*
1.27      djm       142:  * Recursively download 'remote_directory' to 'local_directory'. Preserve
1.18      djm       143:  * times if 'pflag' is set
                    144:  */
1.39    ! djm       145: int sftp_download_dir(struct sftp_conn *, const char *, const char *, Attrib *,
1.37      djm       146:     int, int, int, int, int, int);
1.1       djm       147:
                    148: /*
                    149:  * Upload 'local_path' to 'remote_path'. Preserve permissions and times
                    150:  * if 'pflag' is set
                    151:  */
1.39    ! djm       152: int sftp_upload(struct sftp_conn *, const char *, const char *,
1.37      djm       153:     int, int, int, int);
1.18      djm       154:
                    155: /*
1.27      djm       156:  * Recursively upload 'local_directory' to 'remote_directory'. Preserve
1.18      djm       157:  * times if 'pflag' is set
                    158:  */
1.39    ! djm       159: int sftp_upload_dir(struct sftp_conn *, const char *, const char *,
1.37      djm       160:     int, int, int, int, int, int);
1.31      djm       161:
                    162: /*
                    163:  * Download a 'from_path' from the 'from' connection and upload it to
                    164:  * to 'to' connection at 'to_path'.
                    165:  */
1.39    ! djm       166: int sftp_crossload(struct sftp_conn *from, struct sftp_conn *to,
1.31      djm       167:     const char *from_path, const char *to_path,
                    168:     Attrib *a, int preserve_flag);
                    169:
                    170: /*
                    171:  * Recursively download a directory from 'from_path' from the 'from'
                    172:  * connection and upload it to 'to' connection at 'to_path'.
                    173:  */
1.39    ! djm       174: int sftp_crossload_dir(struct sftp_conn *from, struct sftp_conn *to,
1.31      djm       175:     const char *from_path, const char *to_path,
1.33      djm       176:     Attrib *dirattrib, int preserve_flag, int print_flag,
                    177:     int follow_link_flag);
1.38      djm       178:
                    179: /*
                    180:  * User/group ID to name translation.
                    181:  */
1.39    ! djm       182: int sftp_can_get_users_groups_by_id(struct sftp_conn *conn);
        !           183: int sftp_get_users_groups_by_id(struct sftp_conn *conn,
1.38      djm       184:     const u_int *uids, u_int nuids,
                    185:     const u_int *gids, u_int ngids,
                    186:     char ***usernamesp, char ***groupnamesp);
1.18      djm       187:
                    188: /* Concatenate paths, taking care of slashes. Caller must free result. */
1.39    ! djm       189: char *sftp_path_append(const char *, const char *);
1.29      djm       190:
                    191: /* Make absolute path if relative path and CWD is given. Does not modify
1.35      jsg       192:  * original if the path is already absolute. */
1.39    ! djm       193: char *sftp_make_absolute(char *, const char *);
1.29      djm       194:
                    195: /* Check if remote path is directory */
1.39    ! djm       196: int sftp_remote_is_dir(struct sftp_conn *conn, const char *path);
1.29      djm       197:
                    198: /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
1.39    ! djm       199: int sftp_globpath_is_dir(const char *pathname);
1.9       djm       200:
                    201: #endif