28 #define CONTROL_BUFFER_SIZE 1024
29 #define CREDENTIALS_BUFFER_SIZE 128
58 #define OFFSET(x) offsetof(FTPContext, x)
59 #define D AV_OPT_FLAG_DECODING_PARAM
60 #define E AV_OPT_FLAG_ENCODING_PARAM
62 {
"timeout",
"set timeout of socket I/O operations",
OFFSET(rw_timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
63 {
"ftp-write-seekable",
"control seekability of connection during encoding",
OFFSET(write_seekable),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
E },
64 {
"ftp-anonymous-password",
"password for anonymous login. E-mail address should be used.",
OFFSET(anonymous_password),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
D|
E },
104 if (q > line && q[-1] ==
'\r')
109 if ((q - line) < line_size - 1)
122 int err, i, dash = 0, result = 0, code_found = 0, linesize;
129 while (!code_found || dash) {
138 linesize = strlen(buf);
141 for (i = 0; i < 3; ++i) {
142 if (buf[i] <
'0' || buf[i] >
'9') {
156 for (i = 0; response_codes[i]; ++i) {
157 if (err == response_codes[i]) {
168 if (!dash && buf[3] ==
'-')
170 else if (err == dash && buf[3] ==
' ')
182 const int response_codes[],
char **response)
192 if (response_codes) {
193 return ftp_status(s, response, response_codes);
213 const char *user = NULL, *
pass = NULL;
216 static const int user_codes[] = {331, 230, 0};
217 static const int pass_codes[] = {230, 0};
222 user =
av_strtok(credencials,
":", &end);
230 snprintf(buf,
sizeof(buf),
"USER %s\r\n", user);
234 snprintf(buf,
sizeof(buf),
"PASS %s\r\n", pass);
247 char *res = NULL, *
start = NULL, *
end = NULL;
249 static const char d =
'|';
250 static const char *
command =
"EPSV\r\n";
251 static const int epsv_codes[] = {229, 0};
256 for (i = 0; res[i]; ++i) {
259 }
else if (res[i] ==
')') {
268 if (strlen(start) < 5)
270 if (start[0] != d || start[1] != d || start[2] != d || end[-1] != d)
289 char *res = NULL, *
start = NULL, *
end = NULL;
291 static const char *
command =
"PASV\r\n";
292 static const int pasv_codes[] = {227, 0};
297 for (i = 0; res[i]; ++i) {
300 }
else if (res[i] ==
')') {
310 if (!
av_strtok(start,
",", &end))
goto fail;
311 if (!
av_strtok(end,
",", &end))
goto fail;
312 if (!
av_strtok(end,
",", &end))
goto fail;
313 if (!
av_strtok(end,
",", &end))
goto fail;
317 if (!start)
goto fail;
320 if (!start)
goto fail;
335 char *res = NULL, *
start = NULL, *
end = NULL;
337 static const char *
command =
"PWD\r\n";
338 static const int pwd_codes[] = {257, 0};
343 for (i = 0; res[i]; ++i) {
357 if (end > res && end[-1] ==
'/') {
375 static const int size_codes[] = {213, 0};
377 snprintf(command,
sizeof(command),
"SIZE %s\r\n", s->
path);
379 s->
filesize = strtoll(&res[4], NULL, 10);
393 static const int retr_codes[] = {150, 0};
395 snprintf(command,
sizeof(command),
"RETR %s\r\n", s->
path);
407 static const int stor_codes[] = {150, 0};
409 snprintf(command,
sizeof(command),
"STOR %s\r\n", s->
path);
420 static const char *
command =
"TYPE I\r\n";
421 static const int type_codes[] = {200, 0};
432 static const int rest_codes[] = {350, 0};
434 snprintf(command,
sizeof(command),
"REST %"PRId64
"\r\n", pos);
443 static const char *feat_command =
"FEAT\r\n";
444 static const char *enable_utf8_command =
"OPTS UTF8 ON\r\n";
445 static const int feat_codes[] = {211, 0};
446 static const int opts_codes[] = {200, 451};
462 static const int connect_codes[] = {220, 0};
486 av_log(h,
AV_LOG_WARNING,
"Pure-FTPd server is used as an output protocol. It is known issue this implementation may produce incorrect content and it cannot be fixed at this moment.");
541 static const char *
command =
"ABOR\r\n";
543 static const int abor_codes[] = {225, 226, 0};
583 av_dlog(h,
"ftp protocol open\n");
628 int64_t new_pos, fake_pos;
630 av_dlog(h,
"ftp protocol seek %"PRId64
" %d\n", pos, whence);
670 int read, err, retry_done = 0;
672 av_dlog(h,
"ftp protocol read %d bytes\n", size);
702 if (read <= 0 && s->position < s->filesize && !h->
is_streamed) {
708 if ((err =
ftp_seek(h, pos, SEEK_SET)) < 0) {
730 av_dlog(h,
"ftp protocol write %d bytes\n", size);
755 av_dlog(h,
"ftp protocol close\n");
766 av_dlog(h,
"ftp protocol get_file_handle\n");
778 av_dlog(h,
"ftp protocol shutdown\n");
796 .priv_data_class = &ftp_context_class,