42 #include <sys/types.h>
52 typedef uint32_t uid_t;
55 typedef uint32_t gid_t;
59 typedef _W64 SSIZE_T ssize_t;
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;
74 typedef struct sftp_statvfs_struct* sftp_statvfs_t;
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;
137 struct sftp_request_queue_struct {
138 sftp_request_queue next;
139 sftp_message message;
143 struct sftp_status_message_struct {
152 struct sftp_attributes_struct {
162 uint32_t permissions;
165 uint32_t atime_nseconds;
167 uint32_t createtime_nseconds;
170 uint32_t mtime_nseconds;
172 uint32_t extended_count;
173 ssh_string extended_type;
174 ssh_string extended_data;
177 struct sftp_statvfs_struct {
191 #define LIBSFTP_VERSION 3
200 LIBSSH_API sftp_session
sftp_new(ssh_session session);
207 LIBSSH_API
void sftp_free(sftp_session sftp);
216 LIBSSH_API
int sftp_init(sftp_session sftp);
296 LIBSSH_API sftp_dir
sftp_opendir(sftp_session session,
const char *path);
311 LIBSSH_API sftp_attributes
sftp_readdir(sftp_session session, sftp_dir dir);
334 LIBSSH_API sftp_attributes
sftp_stat(sftp_session session,
const char *path);
349 LIBSSH_API sftp_attributes
sftp_lstat(sftp_session session,
const char *path);
359 LIBSSH_API sftp_attributes
sftp_fstat(sftp_file file);
414 LIBSSH_API sftp_file
sftp_open(sftp_session session,
const char *file,
int accesstype,
417 LIBSSH_API
void sftp_file_set_nonblocking(sftp_file handle);
419 LIBSSH_API
void sftp_file_set_blocking(sftp_file handle);
433 LIBSSH_API ssize_t
sftp_read(sftp_file file,
void *buf,
size_t count);
491 LIBSSH_API
int sftp_async_read(sftp_file file,
void *data, uint32_t len, uint32_t
id);
509 LIBSSH_API ssize_t
sftp_write(sftp_file file,
const void *buf,
size_t count);
520 LIBSSH_API
int sftp_seek(sftp_file file, uint32_t new_offset);
532 LIBSSH_API
int sftp_seek64(sftp_file file, uint64_t new_offset);
543 LIBSSH_API
unsigned long sftp_tell(sftp_file file);
573 LIBSSH_API
int sftp_unlink(sftp_session sftp,
const char *file);
584 LIBSSH_API
int sftp_rmdir(sftp_session sftp,
const char *directory);
599 LIBSSH_API
int sftp_mkdir(sftp_session sftp,
const char *directory, mode_t mode);
614 LIBSSH_API
int sftp_rename(sftp_session sftp,
const char *original,
const char *newname);
628 LIBSSH_API
int sftp_setstat(sftp_session sftp,
const char *file, sftp_attributes attr);
643 LIBSSH_API
int sftp_chown(sftp_session sftp,
const char *file, uid_t owner, gid_t group);
658 LIBSSH_API
int sftp_chmod(sftp_session sftp,
const char *file, mode_t mode);
672 LIBSSH_API
int sftp_utimes(sftp_session sftp,
const char *file,
const struct timeval *times);
685 LIBSSH_API
int sftp_symlink(sftp_session sftp,
const char *target,
const char *dest);
696 LIBSSH_API
char *
sftp_readlink(sftp_session sftp,
const char *path);
707 LIBSSH_API sftp_statvfs_t
sftp_statvfs(sftp_session sftp,
const char *path);
755 LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel chan);
764 LIBSSH_API
int sftp_server_init(sftp_session sftp);
768 #define SFTP_HANDLES 256
769 sftp_packet sftp_packet_read(sftp_session sftp);
770 int sftp_packet_write(sftp_session sftp,uint8_t type, ssh_buffer payload);
771 void sftp_packet_free(sftp_packet packet);
772 int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr);
773 sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,
int expectname);
776 sftp_client_message sftp_get_client_message(sftp_session sftp);
777 void sftp_client_message_free(sftp_client_message msg);
778 int sftp_reply_name(sftp_client_message msg,
const char *name,
779 sftp_attributes attr);
780 int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
781 ssh_string sftp_handle_alloc(sftp_session sftp,
void *info);
782 int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
783 void *sftp_handle(sftp_session sftp, ssh_string handle);
784 int sftp_reply_status(sftp_client_message msg, uint32_t status,
const char *message);
785 int sftp_reply_names_add(sftp_client_message msg,
const char *file,
786 const char *longname, sftp_attributes attr);
787 int sftp_reply_names(sftp_client_message msg);
788 int sftp_reply_data(sftp_client_message msg,
const void *data,
int len);
789 void sftp_handle_remove(sftp_session sftp,
void *handle);
792 #define SSH_FXP_INIT 1
793 #define SSH_FXP_VERSION 2
794 #define SSH_FXP_OPEN 3
795 #define SSH_FXP_CLOSE 4
796 #define SSH_FXP_READ 5
797 #define SSH_FXP_WRITE 6
798 #define SSH_FXP_LSTAT 7
799 #define SSH_FXP_FSTAT 8
800 #define SSH_FXP_SETSTAT 9
801 #define SSH_FXP_FSETSTAT 10
802 #define SSH_FXP_OPENDIR 11
803 #define SSH_FXP_READDIR 12
804 #define SSH_FXP_REMOVE 13
805 #define SSH_FXP_MKDIR 14
806 #define SSH_FXP_RMDIR 15
807 #define SSH_FXP_REALPATH 16
808 #define SSH_FXP_STAT 17
809 #define SSH_FXP_RENAME 18
810 #define SSH_FXP_READLINK 19
811 #define SSH_FXP_SYMLINK 20
813 #define SSH_FXP_STATUS 101
814 #define SSH_FXP_HANDLE 102
815 #define SSH_FXP_DATA 103
816 #define SSH_FXP_NAME 104
817 #define SSH_FXP_ATTRS 105
819 #define SSH_FXP_EXTENDED 200
820 #define SSH_FXP_EXTENDED_REPLY 201
827 #define SSH_FILEXFER_ATTR_SIZE 0x00000001
828 #define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
829 #define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
830 #define SSH_FILEXFER_ATTR_ACMODTIME 0x00000008
831 #define SSH_FILEXFER_ATTR_CREATETIME 0x00000010
832 #define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020
833 #define SSH_FILEXFER_ATTR_ACL 0x00000040
834 #define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080
835 #define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
836 #define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
837 #define SSH_FILEXFER_ATTR_UIDGID 0x00000002
840 #define SSH_FILEXFER_TYPE_REGULAR 1
841 #define SSH_FILEXFER_TYPE_DIRECTORY 2
842 #define SSH_FILEXFER_TYPE_SYMLINK 3
843 #define SSH_FILEXFER_TYPE_SPECIAL 4
844 #define SSH_FILEXFER_TYPE_UNKNOWN 5
858 #define SSH_FX_NO_SUCH_FILE 2
860 #define SSH_FX_PERMISSION_DENIED 3
862 #define SSH_FX_FAILURE 4
864 #define SSH_FX_BAD_MESSAGE 5
866 #define SSH_FX_NO_CONNECTION 6
868 #define SSH_FX_CONNECTION_LOST 7
870 #define SSH_FX_OP_UNSUPPORTED 8
872 #define SSH_FX_INVALID_HANDLE 9
874 #define SSH_FX_NO_SUCH_PATH 10
876 #define SSH_FX_FILE_ALREADY_EXISTS 11
878 #define SSH_FX_WRITE_PROTECT 12
880 #define SSH_FX_NO_MEDIA 13
885 #define SSH_FXF_READ 0x01
886 #define SSH_FXF_WRITE 0x02
887 #define SSH_FXF_APPEND 0x04
888 #define SSH_FXF_CREAT 0x08
889 #define SSH_FXF_TRUNC 0x10
890 #define SSH_FXF_EXCL 0x20
891 #define SSH_FXF_TEXT 0x40
894 #define SSH_FXF_RENAME_OVERWRITE 0x00000001
895 #define SSH_FXF_RENAME_ATOMIC 0x00000002
896 #define SSH_FXF_RENAME_NATIVE 0x00000004
898 #define SFTP_OPEN SSH_FXP_OPEN
899 #define SFTP_CLOSE SSH_FXP_CLOSE
900 #define SFTP_READ SSH_FXP_READ
901 #define SFTP_WRITE SSH_FXP_WRITE
902 #define SFTP_LSTAT SSH_FXP_LSTAT
903 #define SFTP_FSTAT SSH_FXP_FSTAT
904 #define SFTP_SETSTAT SSH_FXP_SETSTAT
905 #define SFTP_FSETSTAT SSH_FXP_FSETSTAT
906 #define SFTP_OPENDIR SSH_FXP_OPENDIR
907 #define SFTP_READDIR SSH_FXP_READDIR
908 #define SFTP_REMOVE SSH_FXP_REMOVE
909 #define SFTP_MKDIR SSH_FXP_MKDIR
910 #define SFTP_RMDIR SSH_FXP_RMDIR
911 #define SFTP_REALPATH SSH_FXP_REALPATH
912 #define SFTP_STAT SSH_FXP_STAT
913 #define SFTP_RENAME SSH_FXP_RENAME
914 #define SFTP_READLINK SSH_FXP_READLINK
915 #define SFTP_SYMLINK SSH_FXP_SYMLINK
918 #define SSH_FXE_STATVFS_ST_RDONLY 0x1
919 #define SSH_FXE_STATVFS_ST_NOSUID 0x2