22 #include <libssh/sftp.h>
55 static const int verbosity = SSH_LOG_NOLOG;
57 char proto[10], path[
MAX_URL_SIZE], hostname[1024], credencials[1024];
58 int port = 22, access,
ret;
60 const char *user = NULL, *
pass = NULL;
65 credencials,
sizeof(credencials),
66 hostname,
sizeof(hostname),
71 if (port <= 0 || port > 65535)
74 if (!(s->
session = ssh_new())) {
80 ssh_options_set(s->
session, SSH_OPTIONS_HOST, hostname);
81 ssh_options_set(s->
session, SSH_OPTIONS_PORT, &port);
82 ssh_options_set(s->
session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
84 ssh_options_set(s->
session, SSH_OPTIONS_TIMEOUT_USEC, &timeout);
86 ssh_options_set(s->
session, SSH_OPTIONS_USER, user);
88 if (ssh_connect(s->
session) != SSH_OK) {
94 if (pass && ssh_userauth_password(s->
session, NULL, pass) != SSH_AUTH_SUCCESS) {
106 if (sftp_init(s->
sftp) != SSH_OK) {
113 access = O_CREAT | O_RDWR;
116 }
else if (flags & AVIO_FLAG_WRITE) {
117 access = O_CREAT | O_WRONLY;
124 if (!(s->
file = sftp_open(s->
sftp, path, access, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH))) {
130 if (!(stat = sftp_fstat(s->
file))) {
135 sftp_attributes_free(stat);
162 newpos = sftp_tell64(s->
file) + pos;
171 if (sftp_seek64(s->
file, newpos)) {
184 if ((bytes_read = sftp_read(s->
file, buf, size)) < 0) {
196 if ((bytes_written = sftp_write(s->
file, buf, size)) < 0) {
200 return bytes_written;
203 #define OFFSET(x) offsetof(LIBSSHContext, x)
204 #define D AV_OPT_FLAG_DECODING_PARAM
205 #define E AV_OPT_FLAG_ENCODING_PARAM
207 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
227 .priv_data_class = &libssh_context_class,