40 #include <sys/types.h>
50 typedef uint32_t uid_t;
53 typedef uint32_t gid_t;
57 typedef _W64 SSIZE_T ssize_t;
62 #define LIBSFTP_VERSION 3
64 typedef struct sftp_attributes_struct* sftp_attributes;
65 typedef struct sftp_client_message_struct* sftp_client_message;
66 typedef struct sftp_dir_struct* sftp_dir;
67 typedef struct sftp_ext_struct *sftp_ext;
68 typedef struct sftp_file_struct* sftp_file;
69 typedef struct sftp_message_struct* sftp_message;
70 typedef struct sftp_packet_struct* sftp_packet;
71 typedef struct sftp_request_queue_struct* sftp_request_queue;
72 typedef struct sftp_session_struct* sftp_session;
73 typedef struct sftp_status_message_struct* sftp_status_message;
76 struct sftp_session_struct {
82 sftp_request_queue queue;
89 struct sftp_packet_struct {
96 struct sftp_file_struct {
105 struct sftp_dir_struct {
114 struct sftp_message_struct {
122 struct sftp_client_message_struct {
128 sftp_attributes attr;
135 ssh_buffer complete_message;
139 struct sftp_request_queue_struct {
140 sftp_request_queue next;
141 sftp_message message;
145 struct sftp_status_message_struct {
154 struct sftp_attributes_struct {
164 uint32_t permissions;
167 uint32_t atime_nseconds;
169 uint32_t createtime_nseconds;
172 uint32_t mtime_nseconds;
174 uint32_t extended_count;
175 ssh_string extended_type;
176 ssh_string extended_data;
205 LIBSSH_API sftp_session
sftp_new(ssh_session session);
217 LIBSSH_API sftp_session
sftp_new_channel(ssh_session session, ssh_channel channel);
225 LIBSSH_API
void sftp_free(sftp_session sftp);
236 LIBSSH_API
int sftp_init(sftp_session sftp);
318 LIBSSH_API sftp_dir
sftp_opendir(sftp_session session,
const char *path);
333 LIBSSH_API sftp_attributes
sftp_readdir(sftp_session session, sftp_dir dir);
358 LIBSSH_API sftp_attributes
sftp_stat(sftp_session session,
const char *path);
375 LIBSSH_API sftp_attributes
sftp_lstat(sftp_session session,
const char *path);
387 LIBSSH_API sftp_attributes
sftp_fstat(sftp_file file);
444 LIBSSH_API sftp_file
sftp_open(sftp_session session,
const char *file,
int accesstype,
475 LIBSSH_API ssize_t
sftp_read(sftp_file file,
void *buf,
size_t count);
533 LIBSSH_API
int sftp_async_read(sftp_file file,
void *data, uint32_t len, uint32_t
id);
551 LIBSSH_API ssize_t
sftp_write(sftp_file file,
const void *buf,
size_t count);
562 LIBSSH_API
int sftp_seek(sftp_file file, uint32_t new_offset);
574 LIBSSH_API
int sftp_seek64(sftp_file file, uint64_t new_offset);
585 LIBSSH_API
unsigned long sftp_tell(sftp_file file);
617 LIBSSH_API
int sftp_unlink(sftp_session sftp,
const char *file);
630 LIBSSH_API
int sftp_rmdir(sftp_session sftp,
const char *directory);
647 LIBSSH_API
int sftp_mkdir(sftp_session sftp,
const char *directory, mode_t mode);
664 LIBSSH_API
int sftp_rename(sftp_session sftp,
const char *original,
const char *newname);
680 LIBSSH_API
int sftp_setstat(sftp_session sftp,
const char *file, sftp_attributes attr);
697 LIBSSH_API
int sftp_chown(sftp_session sftp,
const char *file, uid_t owner, gid_t group);
714 LIBSSH_API
int sftp_chmod(sftp_session sftp,
const char *file, mode_t mode);
730 LIBSSH_API
int sftp_utimes(sftp_session sftp,
const char *file,
const struct timeval *times);
745 LIBSSH_API
int sftp_symlink(sftp_session sftp,
const char *target,
const char *dest);
758 LIBSSH_API
char *
sftp_readlink(sftp_session sftp,
const char *path);
771 LIBSSH_API sftp_statvfs_t
sftp_statvfs(sftp_session sftp,
const char *path);
821 LIBSSH_API sftp_session
sftp_server_new(ssh_session session, ssh_channel chan);
834 #define SFTP_HANDLES 256
835 sftp_packet sftp_packet_read(sftp_session sftp);
836 int sftp_packet_write(sftp_session sftp,uint8_t type, ssh_buffer payload);
837 void sftp_packet_free(sftp_packet packet);
838 int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr);
839 sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,
int expectname);
842 LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp);
843 LIBSSH_API
void sftp_client_message_free(sftp_client_message msg);
844 LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg);
845 LIBSSH_API
const char *sftp_client_message_get_filename(sftp_client_message msg);
846 LIBSSH_API
void sftp_client_message_set_filename(sftp_client_message msg,
const char *newname);
847 LIBSSH_API
const char *sftp_client_message_get_data(sftp_client_message msg);
848 LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg);
849 LIBSSH_API
int sftp_send_client_message(sftp_session sftp, sftp_client_message msg);
850 int sftp_reply_name(sftp_client_message msg,
const char *name,
851 sftp_attributes attr);
852 int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
853 ssh_string sftp_handle_alloc(sftp_session sftp,
void *info);
854 int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
855 void *sftp_handle(sftp_session sftp, ssh_string handle);
856 int sftp_reply_status(sftp_client_message msg, uint32_t status,
const char *message);
857 int sftp_reply_names_add(sftp_client_message msg,
const char *file,
858 const char *longname, sftp_attributes attr);
859 int sftp_reply_names(sftp_client_message msg);
860 int sftp_reply_data(sftp_client_message msg,
const void *data,
int len);
861 void sftp_handle_remove(sftp_session sftp,
void *handle);
864 #define SSH_FXP_INIT 1
865 #define SSH_FXP_VERSION 2
866 #define SSH_FXP_OPEN 3
867 #define SSH_FXP_CLOSE 4
868 #define SSH_FXP_READ 5
869 #define SSH_FXP_WRITE 6
870 #define SSH_FXP_LSTAT 7
871 #define SSH_FXP_FSTAT 8
872 #define SSH_FXP_SETSTAT 9
873 #define SSH_FXP_FSETSTAT 10
874 #define SSH_FXP_OPENDIR 11
875 #define SSH_FXP_READDIR 12
876 #define SSH_FXP_REMOVE 13
877 #define SSH_FXP_MKDIR 14
878 #define SSH_FXP_RMDIR 15
879 #define SSH_FXP_REALPATH 16
880 #define SSH_FXP_STAT 17
881 #define SSH_FXP_RENAME 18
882 #define SSH_FXP_READLINK 19
883 #define SSH_FXP_SYMLINK 20
885 #define SSH_FXP_STATUS 101
886 #define SSH_FXP_HANDLE 102
887 #define SSH_FXP_DATA 103
888 #define SSH_FXP_NAME 104
889 #define SSH_FXP_ATTRS 105
891 #define SSH_FXP_EXTENDED 200
892 #define SSH_FXP_EXTENDED_REPLY 201
899 #define SSH_FILEXFER_ATTR_SIZE 0x00000001
900 #define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
901 #define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
902 #define SSH_FILEXFER_ATTR_ACMODTIME 0x00000008
903 #define SSH_FILEXFER_ATTR_CREATETIME 0x00000010
904 #define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020
905 #define SSH_FILEXFER_ATTR_ACL 0x00000040
906 #define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080
907 #define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
908 #define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
909 #define SSH_FILEXFER_ATTR_UIDGID 0x00000002
912 #define SSH_FILEXFER_TYPE_REGULAR 1
913 #define SSH_FILEXFER_TYPE_DIRECTORY 2
914 #define SSH_FILEXFER_TYPE_SYMLINK 3
915 #define SSH_FILEXFER_TYPE_SPECIAL 4
916 #define SSH_FILEXFER_TYPE_UNKNOWN 5
930 #define SSH_FX_NO_SUCH_FILE 2
932 #define SSH_FX_PERMISSION_DENIED 3
934 #define SSH_FX_FAILURE 4
936 #define SSH_FX_BAD_MESSAGE 5
938 #define SSH_FX_NO_CONNECTION 6
940 #define SSH_FX_CONNECTION_LOST 7
942 #define SSH_FX_OP_UNSUPPORTED 8
944 #define SSH_FX_INVALID_HANDLE 9
946 #define SSH_FX_NO_SUCH_PATH 10
948 #define SSH_FX_FILE_ALREADY_EXISTS 11
950 #define SSH_FX_WRITE_PROTECT 12
952 #define SSH_FX_NO_MEDIA 13
957 #define SSH_FXF_READ 0x01
958 #define SSH_FXF_WRITE 0x02
959 #define SSH_FXF_APPEND 0x04
960 #define SSH_FXF_CREAT 0x08
961 #define SSH_FXF_TRUNC 0x10
962 #define SSH_FXF_EXCL 0x20
963 #define SSH_FXF_TEXT 0x40
966 #define SSH_FXF_RENAME_OVERWRITE 0x00000001
967 #define SSH_FXF_RENAME_ATOMIC 0x00000002
968 #define SSH_FXF_RENAME_NATIVE 0x00000004
970 #define SFTP_OPEN SSH_FXP_OPEN
971 #define SFTP_CLOSE SSH_FXP_CLOSE
972 #define SFTP_READ SSH_FXP_READ
973 #define SFTP_WRITE SSH_FXP_WRITE
974 #define SFTP_LSTAT SSH_FXP_LSTAT
975 #define SFTP_FSTAT SSH_FXP_FSTAT
976 #define SFTP_SETSTAT SSH_FXP_SETSTAT
977 #define SFTP_FSETSTAT SSH_FXP_FSETSTAT
978 #define SFTP_OPENDIR SSH_FXP_OPENDIR
979 #define SFTP_READDIR SSH_FXP_READDIR
980 #define SFTP_REMOVE SSH_FXP_REMOVE
981 #define SFTP_MKDIR SSH_FXP_MKDIR
982 #define SFTP_RMDIR SSH_FXP_RMDIR
983 #define SFTP_REALPATH SSH_FXP_REALPATH
984 #define SFTP_STAT SSH_FXP_STAT
985 #define SFTP_RENAME SSH_FXP_RENAME
986 #define SFTP_READLINK SSH_FXP_READLINK
987 #define SFTP_SYMLINK SSH_FXP_SYMLINK
990 #define SSH_FXE_STATVFS_ST_RDONLY 0x1
991 #define SSH_FXE_STATVFS_ST_NOSUID 0x2