aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libssh/sftp.h34
-rw-r--r--libssh/sftp.c32
-rw-r--r--sample.c12
3 files changed, 77 insertions, 1 deletions
diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h
index 4b23c1e4..a41681b8 100644
--- a/include/libssh/sftp.h
+++ b/include/libssh/sftp.h
@@ -202,6 +202,40 @@ int sftp_init(SFTP_SESSION *sftp);
int sftp_get_error(SFTP_SESSION *sftp);
/**
+ * @brief Get the count of extensions provided by the server.
+ *
+ * @param sftp The sftp session to use.
+ *
+ * @return The count of extensions provided by the server, 0 on error or
+ * not available.
+ */
+unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp);
+
+/**
+ * @brief Get the name of the extension provided by the server.
+ *
+ * @param sftp The sftp session to use.
+ *
+ * @param index The index number of the extension name you want.
+ *
+ * @return The name of the extension.
+ */
+const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int index);
+
+/**
+ * @brief Get the data of the extension provided by the server.
+ *
+ * This is normally the version number of the extension.
+ *
+ * @param sftp The sftp session to use.
+ *
+ * @param index The index number of the extension data you want.
+ *
+ * @return The data of the extension.
+ */
+const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index);
+
+/**
* @brief Open a directory used to obtain directory entries.
*
* @param session The sftp session handle to open the directory.
diff --git a/libssh/sftp.c b/libssh/sftp.c
index 9363955a..d8c46909 100644
--- a/libssh/sftp.c
+++ b/libssh/sftp.c
@@ -587,6 +587,38 @@ int sftp_init(SFTP_SESSION *sftp) {
return 0;
}
+unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp) {
+ if (sftp == NULL || sftp->ext == NULL) {
+ return 0;
+ }
+
+ return sftp->ext->count;
+}
+
+const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int index) {
+ if (sftp == NULL || sftp->ext == NULL || sftp->ext->name == NULL) {
+ return NULL;
+ }
+
+ if (index > sftp->ext->count) {
+ return NULL;
+ }
+
+ return sftp->ext->name[index];
+}
+
+const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index) {
+ if (sftp == NULL || sftp->ext == NULL || sftp->ext->data == NULL) {
+ return NULL;
+ }
+
+ if (index > sftp->ext->count) {
+ return NULL;
+ }
+
+ return sftp->ext->data[index];
+}
+
static REQUEST_QUEUE *request_queue_new(SFTP_MESSAGE *msg) {
REQUEST_QUEUE *queue = NULL;
diff --git a/sample.c b/sample.c
index 3a7acfa0..1a8b0580 100644
--- a/sample.c
+++ b/sample.c
@@ -283,10 +283,12 @@ void do_sftp(SSH_SESSION *session){
SFTP_FILE *fichier;
SFTP_FILE *to;
int len=1;
- int i;
+ unsigned int i;
char data[8000]={0};
char *link;
+ unsigned int count;
+
if(!sftp_session){
fprintf(stderr, "sftp error initialising channel: %s\n",
ssh_get_error(session));
@@ -298,6 +300,14 @@ void do_sftp(SSH_SESSION *session){
return;
}
+ printf("Additional SFTP extensions provided by the server:\n");
+ count = sftp_extensions_get_count(sftp_session);
+ for (i = 0; i < count; i++) {
+ printf("\t%s, version: %s\n",
+ sftp_extensions_get_name(sftp_session, i),
+ sftp_extensions_get_data(sftp_session, i));
+ }
+
/* test symlink and readlink */
if (sftp_symlink(sftp_session, "/tmp/this_is_the_link",
"/tmp/sftp_symlink_test") < 0) {