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_options_parse_config(libssh->
session,
NULL) < 0) {
62 if (ssh_connect(libssh->
session) != SSH_OK) {
76 ssh_options_set(libssh->
session, SSH_OPTIONS_USER, user);
78 if (ssh_userauth_none(libssh->
session,
NULL) == SSH_AUTH_SUCCESS)
81 auth_methods = ssh_userauth_list(libssh->
session,
NULL);
83 if (auth_methods & SSH_AUTH_METHOD_PUBLICKEY) {
86 ssh_private_key priv_key;
88 if (!ssh_try_publickey_from_file(libssh->
session, libssh->
priv_key, &pub_key, &type)) {
89 priv_key = privatekey_from_file(libssh->
session, libssh->
priv_key, type, password);
90 if (ssh_userauth_pubkey(libssh->
session,
NULL, pub_key, priv_key) == SSH_AUTH_SUCCESS) {
91 av_log(libssh,
AV_LOG_DEBUG,
"Authentication successful with selected private key.\n");
98 }
else if (ssh_userauth_autopubkey(libssh->
session, password) == SSH_AUTH_SUCCESS) {
104 if (!authorized && (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;
142 }
else if (flags & AVIO_FLAG_WRITE) {
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], path[
MAX_URL_SIZE], hostname[1024], credencials[1024];
199 credencials,
sizeof(credencials),
200 hostname,
sizeof(hostname),
206 if (port < 0 || port > 65535)
212 user =
av_strtok(credencials,
":", &end);
250 newpos = sftp_tell64(libssh->
file) + pos;
264 if (sftp_seek64(libssh->
file, newpos)) {
277 if ((bytes_read = sftp_read(libssh->
file, buf, size)) < 0) {
289 if ((bytes_written = sftp_write(libssh->
file, buf, size)) < 0) {
293 return bytes_written;
296 #define OFFSET(x) offsetof(LIBSSHContext, x)
297 #define D AV_OPT_FLAG_DECODING_PARAM
298 #define E AV_OPT_FLAG_ENCODING_PARAM
300 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
321 .priv_data_class = &libssh_context_class,
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
static av_cold int libssh_open(URLContext *h, const char *url, int flags)
#define URL_PROTOCOL_FLAG_NETWORK
static int libssh_write(URLContext *h, const unsigned char *buf, int size)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
#define AVIO_FLAG_READ
read-only
#define AVIO_FLAG_WRITE
write-only
Macro definitions for various function/variable attributes.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static av_cold int end(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_cold int libssh_create_ssh_session(LIBSSHContext *libssh, const char *hostname, unsigned int port)
static av_cold int libssh_create_sftp_session(LIBSSHContext *libssh)
static av_cold int libssh_authentication(LIBSSHContext *libssh, const char *user, const char *password)
static av_always_inline av_const double trunc(double x)
static av_cold int libssh_open_file(LIBSSHContext *libssh, int flags, const char *file)
static av_cold int libssh_close(URLContext *h)
static const AVClass libssh_context_class
static int64_t libssh_seek(URLContext *h, int64_t pos, int whence)
Describe the class of an AVClass context structure.
static const AVOption options[]
static int libssh_read(URLContext *h, unsigned char *buf, int size)
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
URLProtocol ff_libssh_protocol
static av_cold void libssh_stat_file(LIBSSHContext *libssh)
unbuffered private I/O API