sftp-client.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* $OpenBSD: sftp-client.h,v 1.28 2019/01/16 23:23:45 djm Exp $ */
  2. /*
  3. * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* Client side of SSH2 filexfer protocol */
  18. #ifndef _SFTP_CLIENT_H
  19. #define _SFTP_CLIENT_H
  20. #ifdef USE_SYSTEM_GLOB
  21. # include <glob.h>
  22. #else
  23. # include "openbsd-compat/glob.h"
  24. #endif
  25. typedef struct SFTP_DIRENT SFTP_DIRENT;
  26. struct SFTP_DIRENT {
  27. char *filename;
  28. char *longname;
  29. Attrib a;
  30. };
  31. /*
  32. * Used for statvfs responses on the wire from the server, because the
  33. * server's native format may be larger than the client's.
  34. */
  35. struct sftp_statvfs {
  36. u_int64_t f_bsize;
  37. u_int64_t f_frsize;
  38. u_int64_t f_blocks;
  39. u_int64_t f_bfree;
  40. u_int64_t f_bavail;
  41. u_int64_t f_files;
  42. u_int64_t f_ffree;
  43. u_int64_t f_favail;
  44. u_int64_t f_fsid;
  45. u_int64_t f_flag;
  46. u_int64_t f_namemax;
  47. };
  48. /*
  49. * Initialise a SSH filexfer connection. Returns NULL on error or
  50. * a pointer to a initialized sftp_conn struct on success.
  51. */
  52. struct sftp_conn *do_init(int, int, u_int, u_int, u_int64_t);
  53. u_int sftp_proto_version(struct sftp_conn *);
  54. /* Close file referred to by 'handle' */
  55. int do_close(struct sftp_conn *, const u_char *, u_int);
  56. /* Read contents of 'path' to NULL-terminated array 'dir' */
  57. int do_readdir(struct sftp_conn *, const char *, SFTP_DIRENT ***);
  58. /* Frees a NULL-terminated array of SFTP_DIRENTs (eg. from do_readdir) */
  59. void free_sftp_dirents(SFTP_DIRENT **);
  60. /* Delete file 'path' */
  61. int do_rm(struct sftp_conn *, const char *);
  62. /* Create directory 'path' */
  63. int do_mkdir(struct sftp_conn *, const char *, Attrib *, int);
  64. /* Remove directory 'path' */
  65. int do_rmdir(struct sftp_conn *, const char *);
  66. /* Get file attributes of 'path' (follows symlinks) */
  67. Attrib *do_stat(struct sftp_conn *, const char *, int);
  68. /* Get file attributes of 'path' (does not follow symlinks) */
  69. Attrib *do_lstat(struct sftp_conn *, const char *, int);
  70. /* Set file attributes of 'path' */
  71. int do_setstat(struct sftp_conn *, const char *, Attrib *);
  72. /* Set file attributes of open file 'handle' */
  73. int do_fsetstat(struct sftp_conn *, const u_char *, u_int, Attrib *);
  74. /* Set file attributes of 'path', not following symlinks */
  75. int do_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a);
  76. /* Canonicalise 'path' - caller must free result */
  77. char *do_realpath(struct sftp_conn *, const char *);
  78. /* Get statistics for filesystem hosting file at "path" */
  79. int do_statvfs(struct sftp_conn *, const char *, struct sftp_statvfs *, int);
  80. /* Rename 'oldpath' to 'newpath' */
  81. int do_rename(struct sftp_conn *, const char *, const char *, int force_legacy);
  82. /* Link 'oldpath' to 'newpath' */
  83. int do_hardlink(struct sftp_conn *, const char *, const char *);
  84. /* Rename 'oldpath' to 'newpath' */
  85. int do_symlink(struct sftp_conn *, const char *, const char *);
  86. /* Call fsync() on open file 'handle' */
  87. int do_fsync(struct sftp_conn *conn, u_char *, u_int);
  88. /*
  89. * Download 'remote_path' to 'local_path'. Preserve permissions and times
  90. * if 'pflag' is set
  91. */
  92. int do_download(struct sftp_conn *, const char *, const char *,
  93. Attrib *, int, int, int);
  94. /*
  95. * Recursively download 'remote_directory' to 'local_directory'. Preserve
  96. * times if 'pflag' is set
  97. */
  98. int download_dir(struct sftp_conn *, const char *, const char *,
  99. Attrib *, int, int, int, int);
  100. /*
  101. * Upload 'local_path' to 'remote_path'. Preserve permissions and times
  102. * if 'pflag' is set
  103. */
  104. int do_upload(struct sftp_conn *, const char *, const char *, int, int, int);
  105. /*
  106. * Recursively upload 'local_directory' to 'remote_directory'. Preserve
  107. * times if 'pflag' is set
  108. */
  109. int upload_dir(struct sftp_conn *, const char *, const char *, int, int, int,
  110. int);
  111. /* Concatenate paths, taking care of slashes. Caller must free result. */
  112. char *path_append(const char *, const char *);
  113. /* Make absolute path if relative path and CWD is given. Does not modify
  114. * original if the the path is already absolute. */
  115. char *make_absolute(char *, const char *);
  116. /* Check if remote path is directory */
  117. int remote_is_dir(struct sftp_conn *conn, const char *path);
  118. /* Check if local path is directory */
  119. int local_is_dir(const char *path);
  120. /* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */
  121. int globpath_is_dir(const char *pathname);
  122. #endif