1 /* sftp headers */ 2 /* 3 Copyright 2003 Aris Adamantiadis 4 5 This file is part of the SSH Library 6 7 The SSH Library is free software; you can redistribute it and/or modify 8 it under the terms of the GNU Lesser General Public License as published by 9 the Free Software Foundation; either version 2.1 of the License, or (at your 10 option) any later version. 11 12 The SSH Library is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 License for more details. 16 17 You should have received a copy of the GNU Lesser General Public License 18 along with the SSH Library; see the file COPYING. If not, write to 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 20 MA 02111-1307, USA. */ 21 22 #ifndef SFTP_H 23 #define SFTP_H 24 #include <libssh/libssh.h> 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 typedef struct sftp_session_struct { 30 SSH_SESSION *session; 31 CHANNEL *channel; 32 int server_version; 33 struct request_queue *queue; 34 u32 id_counter; 35 } SFTP_SESSION ; 36 37 typedef struct { 38 SFTP_SESSION *sftp; 39 u8 type; 40 BUFFER *payload; 41 } SFTP_PACKET; 42 43 /* file handler */ 44 typedef struct sftp_file{ 45 SFTP_SESSION *sftp; 46 char *name; 47 u64 offset; 48 STRING *handle; 49 int eof; 50 int nonblocking; 51 } SFTP_FILE ; 52 53 typedef struct sftp_dir { 54 SFTP_SESSION *sftp; 55 char *name; 56 STRING *handle; /* handle to directory */ 57 BUFFER *buffer; /* contains raw attributes from server which haven't been parsed */ 58 u32 count; /* counts the number of following attributes structures into buffer */ 59 int eof; /* end of directory listing */ 60 } SFTP_DIR; 61 62 typedef struct { 63 SFTP_SESSION *sftp; 64 u8 packet_type; 65 BUFFER *payload; 66 u32 id; 67 } SFTP_MESSAGE; 68 69 typedef struct request_queue{ 70 struct request_queue *next; 71 SFTP_MESSAGE *message; 72 } REQUEST_QUEUE; 73 74 /* SSH_FXP_MESSAGE described into .7 page 26 */ 75 typedef struct { 76 u32 id; 77 u32 status; 78 STRING *error; 79 STRING *lang; 80 char *errormsg; 81 char *langmsg; 82 } STATUS_MESSAGE; 83 84 /* don't worry much of these aren't really used */ 85 typedef struct { 86 char *name; 87 char *longname; /* some weird stuff */ 88 u32 flags; 89 u8 type; 90 u64 size; 91 u32 uid; 92 u32 gid; 93 char *owner; 94 char *group; 95 u32 permissions; 96 u64 atime64; 97 u32 atime; 98 u32 atime_nseconds; 99 u64 createtime; 100 u32 createtime_nseconds; 101 u64 mtime64; 102 u32 mtime; 103 u32 mtime_nseconds; 104 STRING *acl; 105 u32 extended_count; 106 STRING *extended_type; 107 STRING *extended_data; 108 } SFTP_ATTRIBUTES; 109 110 #define LIBSFTP_VERSION 3 111 112 SFTP_SESSION *sftp_new(SSH_SESSION *session); 113 void sftp_free(SFTP_SESSION *sftp); 114 int sftp_init(SFTP_SESSION *sftp); 115 SFTP_DIR *sftp_opendir(SFTP_SESSION *session, char *path); 116 /* reads one file and attribute from opened directory. fails at end */ 117 SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *session, SFTP_DIR *dir); 118 /* returns 1 if the directory was EOF */ 119 int sftp_dir_eof(SFTP_DIR *dir); 120 SFTP_ATTRIBUTES *sftp_stat(SFTP_SESSION *session, char *path); 121 SFTP_ATTRIBUTES *sftp_lstat(SFTP_SESSION *session, char *path); 122 /* sftp_lstat stats a file but doesn't follow symlinks */ 123 SFTP_ATTRIBUTES *sftp_fstat(SFTP_FILE *file); 124 void sftp_attributes_free(SFTP_ATTRIBUTES *file); 125 int sftp_dir_close(SFTP_DIR *dir); 126 int sftp_file_close(SFTP_FILE *file); 127 /* access are the sames than the ones from ansi fopen() */ 128 SFTP_FILE *sftp_open(SFTP_SESSION *session, char *file, int access, SFTP_ATTRIBUTES *attr); 129 int sftp_read(SFTP_FILE *file, void *dest, int len); 130 int sftp_write(SFTP_FILE *file, void *source, int len); 131 void sftp_seek(SFTP_FILE *file, int new_offset); 132 unsigned long sftp_tell(SFTP_FILE *file); 133 void sftp_rewind(SFTP_FILE *file); 134 int sftp_rm(SFTP_SESSION *sftp, char *file); 135 int sftp_rmdir(SFTP_SESSION *sftp, char *directory); 136 int sftp_mkdir(SFTP_SESSION *sftp, char *directory, SFTP_ATTRIBUTES *attr); 137 int sftp_rename(SFTP_SESSION *sftp, char *original, char *newname); 138 int sftp_setstat(SFTP_SESSION *sftp, char *file, SFTP_ATTRIBUTES *attr); 139 char *sftp_canonicalize_path(SFTP_SESSION *sftp, char *path); 140 141 /* SFTP commands and constants */ 142 #define SSH_FXP_INIT 1 143 #define SSH_FXP_VERSION 2 144 #define SSH_FXP_OPEN 3 145 #define SSH_FXP_CLOSE 4 146 #define SSH_FXP_READ 5 147 #define SSH_FXP_WRITE 6 148 #define SSH_FXP_LSTAT 7 149 #define SSH_FXP_FSTAT 8 150 #define SSH_FXP_SETSTAT 9 151 #define SSH_FXP_FSETSTAT 10 152 #define SSH_FXP_OPENDIR 11 153 #define SSH_FXP_READDIR 12 154 #define SSH_FXP_REMOVE 13 155 #define SSH_FXP_MKDIR 14 156 #define SSH_FXP_RMDIR 15 157 #define SSH_FXP_REALPATH 16 158 #define SSH_FXP_STAT 17 159 #define SSH_FXP_RENAME 18 160 #define SSH_FXP_READLINK 19 161 #define SSH_FXP_SYMLINK 20 162 163 #define SSH_FXP_STATUS 101 164 #define SSH_FXP_HANDLE 102 165 #define SSH_FXP_DATA 103 166 #define SSH_FXP_NAME 104 167 #define SSH_FXP_ATTRS 105 168 169 #define SSH_FXP_EXTENDED 200 170 #define SSH_FXP_EXTENDED_REPLY 201 171 172 /* attributes */ 173 /* sftp draft is completely braindead : version 3 and 4 have different flags for same constants */ 174 /* and even worst, version 4 has same flag for 2 different constants */ 175 /* follow up : i won't develop any sftp4 compliant library before having a clarification */ 176 177 #define SSH_FILEXFER_ATTR_SIZE 0x00000001 178 #define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004 179 #define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008 180 #define SSH_FILEXFER_ATTR_ACMODTIME 0x00000008 181 #define SSH_FILEXFER_ATTR_CREATETIME 0x00000010 182 #define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020 183 #define SSH_FILEXFER_ATTR_ACL 0x00000040 184 #define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080 185 #define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100 186 #define SSH_FILEXFER_ATTR_EXTENDED 0x80000000 187 #define SSH_FILEXFER_ATTR_UIDGID 0x00000002 188 189 /* types */ 190 #define SSH_FILEXFER_TYPE_REGULAR 1 191 #define SSH_FILEXFER_TYPE_DIRECTORY 2 192 #define SSH_FILEXFER_TYPE_SYMLINK 3 193 #define SSH_FILEXFER_TYPE_SPECIAL 4 194 #define SSH_FILEXFER_TYPE_UNKNOWN 5 195 196 /* server responses */ 197 #define SSH_FX_OK 0 198 #define SSH_FX_EOF 1 199 #define SSH_FX_NO_SUCH_FILE 2 200 #define SSH_FX_PERMISSION_DENIED 3 201 #define SSH_FX_FAILURE 4 202 #define SSH_FX_BAD_MESSAGE 5 203 #define SSH_FX_NO_CONNECTION 6 204 #define SSH_FX_CONNECTION_LOST 7 205 #define SSH_FX_OP_UNSUPPORTED 8 206 #define SSH_FX_INVALID_HANDLE 9 207 #define SSH_FX_NO_SUCH_PATH 10 208 #define SSH_FX_FILE_ALREADY_EXISTS 11 209 #define SSH_FX_WRITE_PROTECT 12 210 #define SSH_FX_NO_MEDIA 13 211 212 /* file flags */ 213 #define SSH_FXF_READ 0x01 214 #define SSH_FXF_WRITE 0x02 215 #define SSH_FXF_APPEND 0x04 216 #define SSH_FXF_CREAT 0x08 217 #define SSH_FXF_TRUNC 0x10 218 #define SSH_FXF_EXCL 0x20 219 #define SSH_FXF_TEXT 0x40 220 221 #ifdef __cplusplus 222 } ; 223 #endif 224 225 #endif /* SFTP_H */ |