23 #include <libssh/sftp.h>
44 static const int verbosity = SSH_LOG_NOLOG;
46 if (!(libssh->
session = ssh_new())) {
50 ssh_options_set(libssh->
session, SSH_OPTIONS_HOST, hostname);
51 ssh_options_set(libssh->
session, SSH_OPTIONS_PORT, &port);
52 ssh_options_set(libssh->
session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
55 ssh_options_set(libssh->
session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);
58 if (ssh_connect(libssh->
session) != SSH_OK) {
72 ssh_options_set(libssh->
session, SSH_OPTIONS_USER, user);
74 auth_methods = ssh_userauth_list(libssh->
session, NULL);
76 if (auth_methods & SSH_AUTH_METHOD_PUBLICKEY) {
79 ssh_private_key priv_key;
81 if (!ssh_try_publickey_from_file(libssh->
session, libssh->
priv_key, &pub_key, &type)) {
82 priv_key = privatekey_from_file(libssh->
session, libssh->
priv_key, type, password);
83 if (ssh_userauth_pubkey(libssh->
session, NULL, pub_key, priv_key) == SSH_AUTH_SUCCESS) {
84 av_log(libssh,
AV_LOG_DEBUG,
"Authentication successful with selected private key.\n");
91 }
else if (ssh_userauth_autopubkey(libssh->
session, password) == SSH_AUTH_SUCCESS) {
97 if (!authorized && (auth_methods & SSH_AUTH_METHOD_PASSWORD)) {
98 if (ssh_userauth_password(libssh->
session, NULL, password) == SSH_AUTH_SUCCESS) {
119 if (sftp_init(libssh->
sftp) != SSH_OK) {
132 access = O_CREAT | O_RDWR;
135 }
else if (flags & AVIO_FLAG_WRITE) {
136 access = O_CREAT | O_WRONLY;
143 if (!(libssh->
file = sftp_open(libssh->
sftp, file, access, 0666))) {
153 sftp_attributes stat;
155 if (!(stat = sftp_fstat(libssh->
file))) {
160 sftp_attributes_free(stat);
168 sftp_close(libssh->
file);
170 sftp_free(libssh->
sftp);
172 ssh_disconnect(libssh->
session);
181 char proto[10], path[
MAX_URL_SIZE], hostname[1024], credencials[1024];
183 const char *user = NULL, *
pass = NULL;
187 credencials,
sizeof(credencials),
188 hostname,
sizeof(hostname),
193 if (port <= 0 || port > 65535)
199 user =
av_strtok(credencials,
":", &end);
237 newpos = sftp_tell64(libssh->
file) + pos;
251 if (sftp_seek64(libssh->
file, newpos)) {
264 if ((bytes_read = sftp_read(libssh->
file, buf, size)) < 0) {
276 if ((bytes_written = sftp_write(libssh->
file, buf, size)) < 0) {
280 return bytes_written;
283 #define OFFSET(x) offsetof(LIBSSHContext, x)
284 #define D AV_OPT_FLAG_DECODING_PARAM
285 #define E AV_OPT_FLAG_ENCODING_PARAM
287 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
308 .priv_data_class = &libssh_context_class,