/*
* This routine returns ftp server response code.
- * Server may send more than one response for a certain command, following priorities are used:
- * - When pref_codes are set then pref_code is return if occurred. (expected result)
- * - 0 is returned when no pref_codes or not occurred
+ * Server may send more than one response for a certain command.
+ * First expected code is returned.
*/
static int ftp_status(FTPContext *s, char **line, const int response_codes[])
{
return err;
}
- /* consume all messages from server */
+ /* check if server is ready */
if (ftp_status(s, NULL, connect_codes) != 220) {
av_log(h, AV_LOG_ERROR, "FTP server not ready for new users\n");
return AVERROR(EACCES);
if (h->is_streamed)
return AVERROR(EIO);
+ /* XXX: Simulate behaviour of lseek in file protocol, which could be treated as a reference */
new_pos = FFMAX(0, new_pos);
fake_pos = s->filesize != -1 ? FFMIN(new_pos, s->filesize) : new_pos;
av_dlog(h, "ftp protocol read %d bytes\n", size);
retry:
if (s->state == DISCONNECTED) {
+ /* optimization */
if (s->position >= s->filesize)
return 0;
if ((err = ftp_connect_data_connection(h)) < 0)
s->position += read;
if (s->position >= s->filesize) {
/* server will terminate, but keep current position to avoid madness */
+ /* save position to restart from it */
int64_t pos = s->position;
if (ftp_abort(h) < 0) {
s->position = pos;