Go to the documentation of this file.
23 #include <libssh/sftp.h>
46 static const int verbosity = SSH_LOG_NOLOG;
48 if (!(libssh->
session = ssh_new())) {
52 ssh_options_set(libssh->
session, SSH_OPTIONS_HOST, hostname);
53 ssh_options_set(libssh->
session, SSH_OPTIONS_PORT, &port);
54 ssh_options_set(libssh->
session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
57 ssh_options_set(libssh->
session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);
60 if (ssh_options_parse_config(libssh->
session,
NULL) < 0) {
64 if (ssh_connect(libssh->
session) != SSH_OK) {
78 ssh_options_set(libssh->
session, SSH_OPTIONS_USER, user);
80 if (ssh_userauth_none(libssh->
session,
NULL) == SSH_AUTH_SUCCESS)
83 auth_methods = ssh_userauth_list(libssh->
session,
NULL);
85 if (auth_methods & SSH_AUTH_METHOD_PUBLICKEY) {
88 if (ssh_pki_import_privkey_file(libssh->
priv_key, password,
NULL,
NULL, &priv_key) == SSH_OK) {
89 if (ssh_userauth_publickey(libssh->
session,
NULL, priv_key) == SSH_AUTH_SUCCESS) {
90 av_log(libssh,
AV_LOG_DEBUG,
"Authentication successful with selected private key.\n");
97 }
else if (ssh_userauth_publickey_auto(libssh->
session,
NULL, password) == SSH_AUTH_SUCCESS) {
103 if (!authorized && password && (auth_methods & SSH_AUTH_METHOD_PASSWORD)) {
104 if (ssh_userauth_password(libssh->
session,
NULL, password) == SSH_AUTH_SUCCESS) {
125 if (sftp_init(libssh->
sftp) != SSH_OK) {
138 access = O_CREAT | O_RDWR;
142 access = O_CREAT | O_WRONLY;
149 if (!(libssh->
file = sftp_open(libssh->
sftp, file, access, 0666))) {
159 sftp_attributes stat;
161 if (!(stat = sftp_fstat(libssh->
file))) {
166 sftp_attributes_free(stat);
174 sftp_close(libssh->
file);
178 sftp_free(libssh->
sftp);
182 ssh_disconnect(libssh->
session);
192 char proto[10], hostname[1024], credencials[1024];
194 const char *user =
NULL, *pass =
NULL;
198 credencials,
sizeof(credencials),
199 hostname,
sizeof(hostname),
208 if (port < 0 || port > 65535)
214 user =
av_strtok(credencials,
":", &end);
264 newpos = sftp_tell64(libssh->
file) +
pos;
278 if (sftp_seek64(libssh->
file, newpos)) {
291 if ((bytes_read = sftp_read(libssh->
file, buf,
size)) < 0) {
303 if ((bytes_written = sftp_write(libssh->
file, buf,
size)) < 0) {
307 return bytes_written;
319 if (!(libssh->
dir = sftp_opendir(libssh->
sftp, path))) {
335 sftp_attributes attr =
NULL;
344 sftp_attributes_free(attr);
345 attr = sftp_readdir(libssh->
sftp, libssh->
dir);
348 if (sftp_dir_eof(libssh->
dir))
352 }
while (!strcmp(attr->name,
".") || !strcmp(attr->name,
".."));
357 entry->
size = attr->size;
360 entry->
filemode = attr->permissions & 0777;
362 case SSH_FILEXFER_TYPE_REGULAR:
365 case SSH_FILEXFER_TYPE_DIRECTORY:
368 case SSH_FILEXFER_TYPE_SYMLINK:
371 case SSH_FILEXFER_TYPE_SPECIAL:
374 case SSH_FILEXFER_TYPE_UNKNOWN:
378 sftp_attributes_free(attr);
386 sftp_closedir(libssh->
dir);
396 sftp_attributes attr =
NULL;
402 if (!(attr = sftp_stat(libssh->
sftp, path))) {
407 if (attr->type == SSH_FILEXFER_TYPE_DIRECTORY) {
408 if (sftp_rmdir(libssh->
sftp, path) < 0) {
413 if (sftp_unlink(libssh->
sftp, path) < 0) {
423 sftp_attributes_free(attr);
433 char hostname_src[1024], hostname_dst[1024];
434 char credentials_src[1024], credentials_dst[1024];
435 int port_src = 22, port_dst = 22;
438 credentials_src,
sizeof(credentials_src),
439 hostname_src,
sizeof(hostname_src),
441 path_src,
sizeof(path_src),
445 credentials_dst,
sizeof(credentials_dst),
446 hostname_dst,
sizeof(hostname_dst),
448 path_dst,
sizeof(path_dst),
451 if (strcmp(credentials_src, credentials_dst) ||
452 strcmp(hostname_src, hostname_dst) ||
453 port_src != port_dst) {
460 if (sftp_rename(libssh->
sftp, path_src, path_dst) < 0) {
472 #define OFFSET(x) offsetof(LIBSSHContext, x)
473 #define D AV_OPT_FLAG_DECODING_PARAM
474 #define E AV_OPT_FLAG_ENCODING_PARAM
476 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold void libssh_stat_file(LIBSSHContext *libssh)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
char * filename
specified URL
#define URL_PROTOCOL_FLAG_NETWORK
#define AVERROR_EOF
End of file.
static int64_t libssh_seek(URLContext *h, int64_t pos, int whence)
static av_cold void cleanup(FlashSV2Context *s)
int type
Type of the entry.
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
static av_cold int libssh_open(URLContext *h, const char *url, int flags)
static int libssh_delete(URLContext *h)
static int libssh_move(URLContext *h_src, URLContext *h_dst)
int64_t access_timestamp
Time of last access in microseconds since unix epoch, -1 if unknown.
static __device__ float trunc(float a)
int64_t modification_timestamp
Time of last modification in microseconds since unix epoch, -1 if unknown.
static int libssh_open_dir(URLContext *h)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AVIO_ENTRY_SYMBOLIC_LINK
static av_cold int libssh_open_file(LIBSSHContext *libssh, int flags, const char *file)
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 AVIO_FLAG_WRITE
write-only
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int libssh_close_dir(URLContext *h)
static av_cold int libssh_close(URLContext *h)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static int libssh_read(URLContext *h, unsigned char *buf, int size)
static av_cold int libssh_connect(URLContext *h, const char *url, char *path, size_t path_size)
int64_t size
File size in bytes, -1 if unknown.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t group_id
Group ID of owner, -1 if unknown.
int64_t filemode
Unix file mode, -1 if unknown.
static av_cold int libssh_create_sftp_session(LIBSSHContext *libssh)
static const AVOption options[]
static int libssh_read_dir(URLContext *h, AVIODirEntry **next)
static av_cold int libssh_create_ssh_session(LIBSSHContext *libssh, const char *hostname, unsigned int port)
Describes single entry of the directory.
int64_t user_id
User ID of owner, -1 if unknown.
AVIODirEntry * ff_alloc_dir_entry(void)
Allocate directory entry with default values.
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.
const URLProtocol ff_libssh_protocol
static const AVClass libssh_context_class
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 libssh_authentication(LIBSSHContext *libssh, const char *user, const char *password)
static int libssh_write(URLContext *h, const unsigned char *buf, int size)
#define AVIO_FLAG_READ
read-only
char * av_strdup(const char *s)
Duplicate a string.
#define flags(name, subs,...)
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.