1295367Sdes/* $OpenBSD: sftp-client.h,v 1.27 2015/05/08 06:45:13 djm Exp $ */ 276259Sgreen 376259Sgreen/* 4126274Sdes * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 576259Sgreen * 6126274Sdes * Permission to use, copy, modify, and distribute this software for any 7126274Sdes * purpose with or without fee is hereby granted, provided that the above 8126274Sdes * copyright notice and this permission notice appear in all copies. 976259Sgreen * 10126274Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11126274Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12126274Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13126274Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14126274Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15126274Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16126274Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1776259Sgreen */ 1876259Sgreen 1976259Sgreen/* Client side of SSH2 filexfer protocol */ 2076259Sgreen 2192555Sdes#ifndef _SFTP_CLIENT_H 2292555Sdes#define _SFTP_CLIENT_H 2392555Sdes 24296781Sdes#ifdef USE_SYSTEM_GLOB 25296781Sdes# include <glob.h> 26296781Sdes#else 27296781Sdes# include "openbsd-compat/glob.h" 28296781Sdes#endif 29296781Sdes 3076259Sgreentypedef struct SFTP_DIRENT SFTP_DIRENT; 3176259Sgreen 3276259Sgreenstruct SFTP_DIRENT { 3376259Sgreen char *filename; 3476259Sgreen char *longname; 3576259Sgreen Attrib a; 3676259Sgreen}; 3776259Sgreen 3876259Sgreen/* 39181111Sdes * Used for statvfs responses on the wire from the server, because the 40181111Sdes * server's native format may be larger than the client's. 41181111Sdes */ 42181111Sdesstruct sftp_statvfs { 43181111Sdes u_int64_t f_bsize; 44181111Sdes u_int64_t f_frsize; 45181111Sdes u_int64_t f_blocks; 46181111Sdes u_int64_t f_bfree; 47181111Sdes u_int64_t f_bavail; 48181111Sdes u_int64_t f_files; 49181111Sdes u_int64_t f_ffree; 50181111Sdes u_int64_t f_favail; 51181111Sdes u_int64_t f_fsid; 52181111Sdes u_int64_t f_flag; 53181111Sdes u_int64_t f_namemax; 54181111Sdes}; 55181111Sdes 56181111Sdes/* 57149749Sdes * Initialise a SSH filexfer connection. Returns NULL on error or 58146998Sdes * a pointer to a initialized sftp_conn struct on success. 5976259Sgreen */ 60221420Sdesstruct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t); 6176259Sgreen 6299060Sdesu_int sftp_proto_version(struct sftp_conn *); 6392555Sdes 6476259Sgreen/* Close file referred to by 'handle' */ 65295367Sdesint do_close(struct sftp_conn *, const u_char *, u_int); 6676259Sgreen 6776259Sgreen/* Read contents of 'path' to NULL-terminated array 'dir' */ 68295367Sdesint do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***); 6976259Sgreen 7076259Sgreen/* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */ 7192555Sdesvoid free_sftp_dirents(SFTP_DIRENT **); 7276259Sgreen 7376259Sgreen/* Delete file 'path' */ 74295367Sdesint do_rm(struct sftp_conn *, const char *); 7576259Sgreen 7676259Sgreen/* Create directory 'path' */ 77295367Sdesint do_mkdir(struct sftp_conn *, const char *, Attrib *, int); 7876259Sgreen 7976259Sgreen/* Remove directory 'path' */ 80295367Sdesint do_rmdir(struct sftp_conn *, const char *); 8176259Sgreen 8276259Sgreen/* Get file attributes of 'path' (follows symlinks) */ 83295367SdesAttrib *do_stat(struct sftp_conn *, const char *, int); 8476259Sgreen 8576259Sgreen/* Get file attributes of 'path' (does not follow symlinks) */ 86295367SdesAttrib *do_lstat(struct sftp_conn *, const char *, int); 8776259Sgreen 8876259Sgreen/* Set file attributes of 'path' */ 89295367Sdesint do_setstat(struct sftp_conn *, const char *, Attrib *); 9076259Sgreen 9176259Sgreen/* Set file attributes of open file 'handle' */ 92295367Sdesint do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *); 9376259Sgreen 9476259Sgreen/* Canonicalise 'path' - caller must free result */ 95295367Sdeschar *do_realpath(struct sftp_conn *, const char *); 9676259Sgreen 97181111Sdes/* Get statistics for filesystem hosting file at "path" */ 98181111Sdesint do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int); 99181111Sdes 10076259Sgreen/* Rename 'oldpath' to 'newpath' */ 101295367Sdesint do_rename(struct sftp_conn *, const char *, const char *, int force_legacy); 10276259Sgreen 103221420Sdes/* Link 'oldpath' to 'newpath' */ 104295367Sdesint do_hardlink(struct sftp_conn *, const char *, const char *); 105221420Sdes 10676259Sgreen/* Rename 'oldpath' to 'newpath' */ 107295367Sdesint do_symlink(struct sftp_conn *, const char *, const char *); 10876259Sgreen 109262566Sdes/* Call fsync() on open file 'handle' */ 110295367Sdesint do_fsync(struct sftp_conn *conn, u_char *, u_int); 11176259Sgreen 11276259Sgreen/* 11376259Sgreen * Download 'remote_path' to 'local_path'. Preserve permissions and times 11476259Sgreen * if 'pflag' is set 11576259Sgreen */ 116295367Sdesint do_download(struct sftp_conn *, const char *, const char *, 117295367Sdes Attrib *, int, int, int); 11876259Sgreen 11976259Sgreen/* 120295367Sdes * Recursively download 'remote_directory' to 'local_directory'. Preserve 121204917Sdes * times if 'pflag' is set 122204917Sdes */ 123295367Sdesint download_dir(struct sftp_conn *, const char *, const char *, 124295367Sdes Attrib *, int, int, int, int); 125204917Sdes 126204917Sdes/* 12776259Sgreen * Upload 'local_path' to 'remote_path'. Preserve permissions and times 12876259Sgreen * if 'pflag' is set 12976259Sgreen */ 130295367Sdesint do_upload(struct sftp_conn *, const char *, const char *, int, int, int); 13192555Sdes 132204917Sdes/* 133295367Sdes * Recursively upload 'local_directory' to 'remote_directory'. Preserve 134204917Sdes * times if 'pflag' is set 135204917Sdes */ 136295367Sdesint upload_dir(struct sftp_conn *, const char *, const char *, int, int, int, 137295367Sdes int); 138204917Sdes 139204917Sdes/* Concatenate paths, taking care of slashes. Caller must free result. */ 140295367Sdeschar *path_append(const char *, const char *); 141204917Sdes 14292555Sdes#endif 143