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 if (ssh_userauth_none(libssh->
session,
NULL) == SSH_AUTH_SUCCESS)
77 auth_methods = ssh_userauth_list(libssh->
session,
NULL);
79 if (auth_methods & SSH_AUTH_METHOD_PUBLICKEY) {
82 ssh_private_key priv_key;
84 if (!ssh_try_publickey_from_file(libssh->
session, libssh->
priv_key, &pub_key, &type)) {
85 priv_key = privatekey_from_file(libssh->
session, libssh->
priv_key, type, password);
86 if (ssh_userauth_pubkey(libssh->
session,
NULL, pub_key, priv_key) == SSH_AUTH_SUCCESS) {
87 av_log(libssh,
AV_LOG_DEBUG,
"Authentication successful with selected private key.\n");
94 }
else if (ssh_userauth_autopubkey(libssh->
session, password) == SSH_AUTH_SUCCESS) {
100 if (!authorized && (auth_methods & SSH_AUTH_METHOD_PASSWORD)) {
101 if (ssh_userauth_password(libssh->
session,
NULL, password) == SSH_AUTH_SUCCESS) {
122 if (sftp_init(libssh->
sftp) != SSH_OK) {
135 access = O_CREAT | O_RDWR;
138 }
else if (flags & AVIO_FLAG_WRITE) {
139 access = O_CREAT | O_WRONLY;
146 if (!(libssh->
file = sftp_open(libssh->
sftp, file, access, 0666))) {
156 sftp_attributes stat;
158 if (!(stat = sftp_fstat(libssh->
file))) {
163 sftp_attributes_free(stat);
171 sftp_close(libssh->
file);
175 sftp_free(libssh->
sftp);
179 ssh_disconnect(libssh->
session);
189 char proto[10], path[
MAX_URL_SIZE], hostname[1024], credencials[1024];
195 credencials,
sizeof(credencials),
196 hostname,
sizeof(hostname),
201 if (port <= 0 || port > 65535)
207 user =
av_strtok(credencials,
":", &end);
245 newpos = sftp_tell64(libssh->
file) + pos;
259 if (sftp_seek64(libssh->
file, newpos)) {
272 if ((bytes_read = sftp_read(libssh->
file, buf, size)) < 0) {
284 if ((bytes_written = sftp_write(libssh->
file, buf, size)) < 0) {
288 return bytes_written;
291 #define OFFSET(x) offsetof(LIBSSHContext, x)
292 #define D AV_OPT_FLAG_DECODING_PARAM
293 #define E AV_OPT_FLAG_ENCODING_PARAM
295 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
316 .priv_data_class = &libssh_context_class,