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 },
484 .class_name =
"libssh",
#define AVIO_FLAG_READ
read-only
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
#define AVIO_FLAG_WRITE
write-only
@ AVIO_ENTRY_SYMBOLIC_LINK
#define flags(name, subs,...)
static __device__ float trunc(float a)
static av_cold void cleanup(FlashSV2Context *s)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
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.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
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().
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
#define LIBAVUTIL_VERSION_INT
Macro definitions for various function/variable attributes.
static const AVClass libssh_context_class
static av_cold int libssh_open(URLContext *h, const char *url, int flags)
static int libssh_delete(URLContext *h)
static int libssh_read(URLContext *h, unsigned char *buf, int size)
static int libssh_open_dir(URLContext *h)
const URLProtocol ff_libssh_protocol
static int64_t libssh_seek(URLContext *h, int64_t pos, int whence)
static av_cold void libssh_stat_file(LIBSSHContext *libssh)
static int libssh_move(URLContext *h_src, URLContext *h_dst)
static av_cold int libssh_create_sftp_session(LIBSSHContext *libssh)
static av_cold int libssh_open_file(LIBSSHContext *libssh, int flags, const char *file)
static int libssh_read_dir(URLContext *h, AVIODirEntry **next)
static av_cold int libssh_close(URLContext *h)
static av_cold int libssh_authentication(LIBSSHContext *libssh, const char *user, const char *password)
static av_cold int libssh_create_ssh_session(LIBSSHContext *libssh, const char *hostname, unsigned int port)
static int libssh_close_dir(URLContext *h)
static av_cold int libssh_connect(URLContext *h, const char *url, char *path, size_t path_size)
static int libssh_write(URLContext *h, const unsigned char *buf, int size)
Memory handling functions.
Describe the class of an AVClass context structure.
Describes single entry of the directory.
char * filename
specified URL
AVIODirEntry * ff_alloc_dir_entry(void)
Allocate directory entry with default values.
unbuffered private I/O API
#define URL_PROTOCOL_FLAG_NETWORK