23 #include <libssh/sftp.h> 
   47     static const int verbosity = SSH_LOG_NOLOG;
 
   49     if (!(libssh->
session = ssh_new())) {
 
   53     ssh_options_set(libssh->
session, SSH_OPTIONS_HOST, hostname);
 
   54     ssh_options_set(libssh->
session, SSH_OPTIONS_PORT, &port);
 
   55     ssh_options_set(libssh->
session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
 
   58         ssh_options_set(libssh->
session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);
 
   61     if (ssh_options_parse_config(libssh->
session, 
NULL) < 0) {
 
   65     if (ssh_connect(libssh->
session) != SSH_OK) {
 
   79         ssh_options_set(libssh->
session, SSH_OPTIONS_USER, user);
 
   81     if (ssh_userauth_none(libssh->
session, 
NULL) == SSH_AUTH_SUCCESS)
 
   84     auth_methods = ssh_userauth_list(libssh->
session, 
NULL);
 
   86     if (auth_methods & SSH_AUTH_METHOD_PUBLICKEY) {
 
   89             if (ssh_pki_import_privkey_file(libssh->
priv_key, password, 
NULL, 
NULL, &priv_key) == SSH_OK) {
 
   90                 if (ssh_userauth_publickey(libssh->
session, 
NULL, priv_key) == SSH_AUTH_SUCCESS) {
 
   91                     av_log(libssh, 
AV_LOG_DEBUG, 
"Authentication successful with selected private key.\n");
 
   98         } 
else if (ssh_userauth_publickey_auto(libssh->
session, 
NULL, password) == SSH_AUTH_SUCCESS) {
 
  104     if (!authorized && password && (auth_methods & SSH_AUTH_METHOD_PASSWORD)) {
 
  105         if (ssh_userauth_password(libssh->
session, 
NULL, password) == SSH_AUTH_SUCCESS) {
 
  126     if (sftp_init(libssh->
sftp) != SSH_OK) {
 
  139         access = O_CREAT | O_RDWR;
 
  143         access = O_CREAT | O_WRONLY;
 
  150     if (!(libssh->
file = sftp_open(libssh->
sftp, file, access, 0666))) {
 
  160     sftp_attributes stat;
 
  162     if (!(stat = sftp_fstat(libssh->
file))) {
 
  167         sftp_attributes_free(stat);
 
  175         sftp_close(libssh->
file);
 
  179         sftp_free(libssh->
sftp);
 
  183         ssh_disconnect(libssh->
session);
 
  193     char proto[10], hostname[1024], credentials[1024];
 
  195     const char *user = 
NULL, *pass = 
NULL;
 
  199                  credentials, 
sizeof(credentials),
 
  200                  hostname, 
sizeof(hostname),
 
  209     if (port < 0 || port > 65535)
 
  215     user = 
av_strtok(credentials, 
":", &end);
 
  265         newpos = sftp_tell64(libssh->
file) + 
pos;
 
  279     if (sftp_seek64(libssh->
file, newpos)) {
 
  292     if ((bytes_read = sftp_read(libssh->
file, buf, 
size)) < 0) {
 
  304     if ((bytes_written = sftp_write(libssh->
file, buf, 
size)) < 0) {
 
  308     return bytes_written;
 
  320     if (!(libssh->
dir = sftp_opendir(libssh->
sftp, path))) {
 
  336     sftp_attributes attr = 
NULL;
 
  345             sftp_attributes_free(attr);
 
  346         attr = sftp_readdir(libssh->
sftp, libssh->
dir);
 
  349             if (sftp_dir_eof(libssh->
dir))
 
  353     } 
while (!strcmp(attr->name, 
".") || !strcmp(attr->name, 
".."));
 
  356     entry->group_id = attr->gid;
 
  357     entry->user_id = attr->uid;
 
  358     entry->size = attr->size;
 
  359     entry->access_timestamp = INT64_C(1000000) * attr->atime;
 
  360     entry->modification_timestamp = INT64_C(1000000) * attr->mtime;
 
  361     entry->filemode = attr->permissions & 0777;
 
  363     case SSH_FILEXFER_TYPE_REGULAR:
 
  366     case SSH_FILEXFER_TYPE_DIRECTORY:
 
  369     case SSH_FILEXFER_TYPE_SYMLINK:
 
  372     case SSH_FILEXFER_TYPE_SPECIAL:
 
  375     case SSH_FILEXFER_TYPE_UNKNOWN:
 
  379     sftp_attributes_free(attr);
 
  387         sftp_closedir(libssh->
dir);
 
  397     sftp_attributes attr = 
NULL;
 
  403     if (!(attr = sftp_stat(libssh->
sftp, path))) {
 
  408     if (attr->type == SSH_FILEXFER_TYPE_DIRECTORY) {
 
  409         if (sftp_rmdir(libssh->
sftp, path) < 0) {
 
  414         if (sftp_unlink(libssh->
sftp, path) < 0) {
 
  424         sftp_attributes_free(attr);
 
  434     char hostname_src[1024], hostname_dst[1024];
 
  435     char credentials_src[1024], credentials_dst[1024];
 
  436     int port_src = 22, port_dst = 22;
 
  439                  credentials_src, 
sizeof(credentials_src),
 
  440                  hostname_src, 
sizeof(hostname_src),
 
  442                  path_src, 
sizeof(path_src),
 
  446                  credentials_dst, 
sizeof(credentials_dst),
 
  447                  hostname_dst, 
sizeof(hostname_dst),
 
  449                  path_dst, 
sizeof(path_dst),
 
  452     if (strcmp(credentials_src, credentials_dst) ||
 
  453             strcmp(hostname_src, hostname_dst) ||
 
  454             port_src != port_dst) {
 
  461     if (sftp_rename(libssh->
sftp, path_src, path_dst) < 0) {
 
  473 #define OFFSET(x) offsetof(LIBSSHContext, x) 
  474 #define D AV_OPT_FLAG_DECODING_PARAM 
  475 #define E AV_OPT_FLAG_ENCODING_PARAM 
  477     {
"timeout", 
"set timeout of socket I/O operations", 
OFFSET(rw_timeout), 
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, 
D|
E },