1*7c478bd9Sstevel@tonic-gate /* $OpenBSD: sftp-client.h,v 1.11 2002/09/11 22:41:50 djm Exp $ */ 2*7c478bd9Sstevel@tonic-gate 3*7c478bd9Sstevel@tonic-gate #ifndef _SFTP_CLIENT_H 4*7c478bd9Sstevel@tonic-gate #define _SFTP_CLIENT_H 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*7c478bd9Sstevel@tonic-gate 8*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 9*7c478bd9Sstevel@tonic-gate extern "C" { 10*7c478bd9Sstevel@tonic-gate #endif 11*7c478bd9Sstevel@tonic-gate 12*7c478bd9Sstevel@tonic-gate 13*7c478bd9Sstevel@tonic-gate /* 14*7c478bd9Sstevel@tonic-gate * Copyright (c) 2001,2002 Damien Miller. All rights reserved. 15*7c478bd9Sstevel@tonic-gate * 16*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 17*7c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 18*7c478bd9Sstevel@tonic-gate * are met: 19*7c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 20*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 21*7c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 22*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 23*7c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 24*7c478bd9Sstevel@tonic-gate * 25*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26*7c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27*7c478bd9Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28*7c478bd9Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29*7c478bd9Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30*7c478bd9Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31*7c478bd9Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32*7c478bd9Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33*7c478bd9Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate /* Client side of SSH2 filexfer protocol */ 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate typedef struct SFTP_DIRENT SFTP_DIRENT; 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate struct SFTP_DIRENT { 42*7c478bd9Sstevel@tonic-gate char *filename; 43*7c478bd9Sstevel@tonic-gate char *longname; 44*7c478bd9Sstevel@tonic-gate Attrib a; 45*7c478bd9Sstevel@tonic-gate }; 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /* 48*7c478bd9Sstevel@tonic-gate * Initialiase a SSH filexfer connection. Returns -1 on error or 49*7c478bd9Sstevel@tonic-gate * protocol version on success. 50*7c478bd9Sstevel@tonic-gate */ 51*7c478bd9Sstevel@tonic-gate struct sftp_conn *do_init(int, int, u_int, u_int); 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate u_int sftp_proto_version(struct sftp_conn *); 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate /* Close file referred to by 'handle' */ 56*7c478bd9Sstevel@tonic-gate int do_close(struct sftp_conn *, char *, u_int); 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* Read contents of 'path' to NULL-terminated array 'dir' */ 59*7c478bd9Sstevel@tonic-gate int do_readdir(struct sftp_conn *, char *, SFTP_DIRENT ***); 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */ 62*7c478bd9Sstevel@tonic-gate void free_sftp_dirents(SFTP_DIRENT **); 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate /* Delete file 'path' */ 65*7c478bd9Sstevel@tonic-gate int do_rm(struct sftp_conn *, char *); 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* Create directory 'path' */ 68*7c478bd9Sstevel@tonic-gate int do_mkdir(struct sftp_conn *, char *, Attrib *); 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* Remove directory 'path' */ 71*7c478bd9Sstevel@tonic-gate int do_rmdir(struct sftp_conn *, char *); 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate /* Get file attributes of 'path' (follows symlinks) */ 74*7c478bd9Sstevel@tonic-gate Attrib *do_stat(struct sftp_conn *, char *, int); 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* Get file attributes of 'path' (does not follow symlinks) */ 77*7c478bd9Sstevel@tonic-gate Attrib *do_lstat(struct sftp_conn *, char *, int); 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* Get file attributes of open file 'handle' */ 80*7c478bd9Sstevel@tonic-gate Attrib *do_fstat(struct sftp_conn *, char *, u_int, int); 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* Set file attributes of 'path' */ 83*7c478bd9Sstevel@tonic-gate int do_setstat(struct sftp_conn *, char *, Attrib *); 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate /* Set file attributes of open file 'handle' */ 86*7c478bd9Sstevel@tonic-gate int do_fsetstat(struct sftp_conn *, char *, u_int, Attrib *); 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate /* Canonicalise 'path' - caller must free result */ 89*7c478bd9Sstevel@tonic-gate char *do_realpath(struct sftp_conn *, char *); 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* Rename 'oldpath' to 'newpath' */ 92*7c478bd9Sstevel@tonic-gate int do_rename(struct sftp_conn *, char *, char *); 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* Rename 'oldpath' to 'newpath' */ 95*7c478bd9Sstevel@tonic-gate int do_symlink(struct sftp_conn *, char *, char *); 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* Return target of symlink 'path' - caller must free result */ 98*7c478bd9Sstevel@tonic-gate char *do_readlink(struct sftp_conn *, char *); 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate /* XXX: add callbacks to do_download/do_upload so we can do progress meter */ 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate /* 103*7c478bd9Sstevel@tonic-gate * Download 'remote_path' to 'local_path'. Preserve permissions and times 104*7c478bd9Sstevel@tonic-gate * if 'pflag' is set 105*7c478bd9Sstevel@tonic-gate */ 106*7c478bd9Sstevel@tonic-gate int do_download(struct sftp_conn *, char *, char *, int); 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* 109*7c478bd9Sstevel@tonic-gate * Upload 'local_path' to 'remote_path'. Preserve permissions and times 110*7c478bd9Sstevel@tonic-gate * if 'pflag' is set 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate int do_upload(struct sftp_conn *, char *, char *, int); 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 115*7c478bd9Sstevel@tonic-gate } 116*7c478bd9Sstevel@tonic-gate #endif 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate #endif /* _SFTP_CLIENT_H */ 119