Lines Matching defs:libssh
23 #include <libssh/sftp.h>
44 static av_cold int libssh_create_ssh_session(LIBSSHContext *libssh, const char* hostname, unsigned int port)
48 if (!(libssh->session = ssh_new())) {
49 av_log(libssh, AV_LOG_ERROR, "SSH session creation failed: %s\n", ssh_get_error(libssh->session));
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);
55 if (libssh->rw_timeout > 0) {
56 long timeout = libssh->rw_timeout * 1000;
57 ssh_options_set(libssh->session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);
60 if (ssh_options_parse_config(libssh->session, NULL) < 0) {
61 av_log(libssh, AV_LOG_WARNING, "Could not parse the config file.\n");
64 if (ssh_connect(libssh->session) != SSH_OK) {
65 av_log(libssh, AV_LOG_ERROR, "Connection failed: %s\n", ssh_get_error(libssh->session));
72 static av_cold int libssh_authentication(LIBSSHContext *libssh, const char *user, const char *password)
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);
86 if (libssh->priv_key) {
90 if (!ssh_try_publickey_from_file(libssh->session, libssh->priv_key, &pub_key, &type)) {
91 priv_key = privatekey_from_file(libssh->session, libssh->priv_key, type, password);
92 if (ssh_userauth_pubkey(libssh->session, NULL, pub_key, priv_key) == SSH_AUTH_SUCCESS) {
93 av_log(libssh, AV_LOG_DEBUG, "Authentication successful with selected private key.\n");
97 av_log(libssh, AV_LOG_DEBUG, "Invalid key is provided.\n");
100 } else if (ssh_userauth_autopubkey(libssh->session, password) == SSH_AUTH_SUCCESS) {
101 av_log(libssh, AV_LOG_DEBUG, "Authentication successful with auto selected key.\n");
107 if (ssh_userauth_password(libssh->session, NULL, password) == SSH_AUTH_SUCCESS) {
108 av_log(libssh, AV_LOG_DEBUG, "Authentication successful with password.\n");
114 av_log(libssh, AV_LOG_ERROR, "Authentication failed.\n");
121 static av_cold int libssh_create_sftp_session(LIBSSHContext *libssh)
123 if (!(libssh->sftp = sftp_new(libssh->session))) {
124 av_log(libssh, AV_LOG_ERROR, "SFTP session creation failed: %s\n", ssh_get_error(libssh->session));
128 if (sftp_init(libssh->sftp) != SSH_OK) {
129 av_log(libssh, AV_LOG_ERROR, "Error initializing sftp session: %s\n", ssh_get_error(libssh->session));
136 static av_cold int libssh_open_file(LIBSSHContext *libssh, int flags, const char *file)
142 if (libssh->trunc)
146 if (libssh->trunc)
152 if (!(libssh->file = sftp_open(libssh->sftp, file, access, 0666))) {
153 av_log(libssh, AV_LOG_ERROR, "Error opening sftp file: %s\n", ssh_get_error(libssh->session));
160 static av_cold void libssh_stat_file(LIBSSHContext *libssh)
164 if (!(stat = sftp_fstat(libssh->file))) {
165 av_log(libssh, AV_LOG_WARNING, "Cannot stat remote file.\n");
166 libssh->filesize = -1;
168 libssh->filesize = stat->size;
175 LIBSSHContext *libssh = h->priv_data;
176 if (libssh->file) {
177 sftp_close(libssh->file);
178 libssh->file = NULL;
180 if (libssh->sftp) {
181 sftp_free(libssh->sftp);
182 libssh->sftp = NULL;
184 if (libssh->session) {
185 ssh_disconnect(libssh->session);
186 ssh_free(libssh->session);
187 libssh->session = NULL;
194 LIBSSHContext *libssh = h->priv_data;
214 if ((ret = libssh_create_ssh_session(libssh, hostname, port)) < 0)
220 if ((ret = libssh_authentication(libssh, user, pass)) < 0)
223 if ((ret = libssh_create_sftp_session(libssh)) < 0)
232 LIBSSHContext *libssh = h->priv_data;
238 if ((ret = libssh_open_file(libssh, flags, path)) < 0)
241 libssh_stat_file(libssh);
252 LIBSSHContext *libssh = h->priv_data;
255 if (libssh->filesize == -1 && (whence == AVSEEK_SIZE || whence == SEEK_END)) {
262 return libssh->filesize;
267 newpos = sftp_tell64(libssh->file) + pos;
270 newpos = libssh->filesize + pos;
281 if (sftp_seek64(libssh->file, newpos)) {
291 LIBSSHContext *libssh = h->priv_data;
294 if ((bytes_read = sftp_read(libssh->file, buf, size)) < 0) {
295 av_log(libssh, AV_LOG_ERROR, "Read error.\n");
303 LIBSSHContext *libssh = h->priv_data;
306 if ((bytes_written = sftp_write(libssh->file, buf, size)) < 0) {
307 av_log(libssh, AV_LOG_ERROR, "Write error.\n");
315 LIBSSHContext *libssh = h->priv_data;
322 if (!(libssh->dir = sftp_opendir(libssh->sftp, path))) {
323 av_log(libssh, AV_LOG_ERROR, "Error opening sftp dir: %s\n", ssh_get_error(libssh->session));
337 LIBSSHContext *libssh = h->priv_data;
348 attr = sftp_readdir(libssh->sftp, libssh->dir);
351 if (sftp_dir_eof(libssh->dir))
387 LIBSSHContext *libssh = h->priv_data;
388 if (libssh->dir)
389 sftp_closedir(libssh->dir);
390 libssh->dir = NULL;
398 LIBSSHContext *libssh = h->priv_data;
405 if (!(attr = sftp_stat(libssh->sftp, path))) {
406 ret = AVERROR(sftp_get_error(libssh->sftp));
411 if (sftp_rmdir(libssh->sftp, path) < 0) {
412 ret = AVERROR(sftp_get_error(libssh->sftp));
416 if (sftp_unlink(libssh->sftp, path) < 0) {
417 ret = AVERROR(sftp_get_error(libssh->sftp));
434 LIBSSHContext *libssh = h_src->priv_data;
463 if (sftp_rename(libssh->sftp, path_src, path_dst) < 0) {
464 ret = AVERROR(sftp_get_error(libssh->sftp));
486 .class_name = "libssh",