|
|
@ -1,8 +1,8 @@ |
|
|
|
#include <libssh/libssh.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <unistd.h> |
|
|
|
#include <string.h> |
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
int verify_host(ssh_session session) { |
|
|
|
enum ssh_known_hosts_e state; |
|
|
@ -20,13 +20,13 @@ int verify_host(ssh_session session) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int get_movies(ssh_session session, char** buffer, size_t size) { |
|
|
|
int get_movies(ssh_session session, char **buffer, size_t size) { |
|
|
|
ssh_channel channel; |
|
|
|
int rc; |
|
|
|
char read_buffer[256]; |
|
|
|
int nbytes; |
|
|
|
size_t len = 0; |
|
|
|
char* temp; |
|
|
|
char *temp; |
|
|
|
|
|
|
|
channel = ssh_channel_new(session); |
|
|
|
if (channel == NULL) |
|
|
@ -39,7 +39,8 @@ int get_movies(ssh_session session, char** buffer, size_t size) { |
|
|
|
return rc; |
|
|
|
} |
|
|
|
|
|
|
|
rc = ssh_channel_request_exec(channel, "find /var/www/public/media -type f -name \"*mp4\""); |
|
|
|
rc = ssh_channel_request_exec( |
|
|
|
channel, "find /var/www/public/media -type f -name \"*mp4\""); |
|
|
|
if (rc != SSH_OK) { |
|
|
|
fprintf(stderr, "Failed to request exec"); |
|
|
|
ssh_channel_close(channel); |
|
|
@ -49,11 +50,9 @@ int get_movies(ssh_session session, char** buffer, size_t size) { |
|
|
|
|
|
|
|
nbytes = ssh_channel_read(channel, read_buffer, sizeof(read_buffer), 0); |
|
|
|
while (nbytes > 0) { |
|
|
|
fprintf(stderr, "size: %li\tlen: %li\tnbytes: %d\n", size, len, nbytes); |
|
|
|
if ((len+=nbytes) > size) { |
|
|
|
fprintf(stderr, "new len: %li\n", len); |
|
|
|
char* temp = realloc(*buffer, len); |
|
|
|
if ((len += nbytes) > size) { |
|
|
|
size = len; |
|
|
|
temp = realloc(*buffer, len); |
|
|
|
if (!temp) { |
|
|
|
fprintf(stderr, "Failed to reallocate char buffer"); |
|
|
|
ssh_channel_close(channel); |
|
|
@ -63,7 +62,7 @@ int get_movies(ssh_session session, char** buffer, size_t size) { |
|
|
|
*buffer = temp; |
|
|
|
} |
|
|
|
|
|
|
|
*buffer = strcat(*buffer, read_buffer); |
|
|
|
memcpy(*buffer + len - nbytes, read_buffer, nbytes); |
|
|
|
|
|
|
|
nbytes = ssh_channel_read(channel, read_buffer, sizeof(read_buffer), 0); |
|
|
|
|
|
|
@ -127,15 +126,13 @@ int main(int argc, char *argv[]) { |
|
|
|
} |
|
|
|
|
|
|
|
int size = 16; |
|
|
|
char* b = malloc(size); |
|
|
|
char *b = malloc(size); |
|
|
|
memset(b, 0, size); |
|
|
|
if (get_movies(session, &b, size) != SSH_OK) { |
|
|
|
fprintf(stderr, "Unable to list movies: %s\n", ssh_get_error(session)); |
|
|
|
exit(-1); |
|
|
|
} |
|
|
|
|
|
|
|
fprintf(stdout, "%s", b); |
|
|
|
|
|
|
|
ssh_disconnect(session); |
|
|
|
ssh_free(session); |
|
|
|
} |
|
|
|