summaryrefslogtreecommitdiff
path: root/libavformat/ftp.c
diff options
context:
space:
mode:
authorMariusz SzczepaƄczyk <mszczepanczyk@gmail.com>2015-08-19 23:52:14 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2015-08-20 00:08:16 +0200
commitbf5b2f9df8761083281ef0e93afc8fa8d1f9f60a (patch)
tree0b913abe7e5d7472b6b499d5b38c5aa6b646c810 /libavformat/ftp.c
parent034e6fbd9cdbd4eddbe8dbea287a46880c6c6042 (diff)
downloadffmpeg-bf5b2f9df8761083281ef0e93afc8fa8d1f9f60a.tar.gz
lavf/ftp: implement move and delete callbacks
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/ftp.c')
-rw-r--r--libavformat/ftp.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/libavformat/ftp.c b/libavformat/ftp.c
index db233c9b4b..51f491ce08 100644
--- a/libavformat/ftp.c
+++ b/libavformat/ftp.c
@@ -1038,6 +1038,65 @@ static int ftp_close_dir(URLContext *h)
return 0;
}
+static int ftp_delete(URLContext *h)
+{
+ FTPContext *s = h->priv_data;
+ char command[MAX_URL_SIZE];
+ static const int del_codes[] = {250, 421, 450, 500, 501, 502, 530, 550, 0};
+ static const int rmd_codes[] = {250, 421, 500, 501, 502, 530, 550, 0};
+ int ret;
+
+ if ((ret = ftp_connect(h, h->filename)) < 0)
+ goto cleanup;
+
+ snprintf(command, sizeof(command), "DELE %s\r\n", s->path);
+ if (ftp_send_command(s, command, del_codes, NULL) == 250) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ snprintf(command, sizeof(command), "RMD %s\r\n", s->path);
+ if (ftp_send_command(s, command, rmd_codes, NULL) == 250)
+ ret = 0;
+ else
+ ret = AVERROR(EIO);
+
+cleanup:
+ ftp_close(h);
+ return ret;
+}
+
+static int ftp_move(URLContext *h_src, URLContext *h_dst)
+{
+ FTPContext *s = h_src->priv_data;
+ char command[MAX_URL_SIZE], path[MAX_URL_SIZE];
+ static const int rnfr_codes[] = {350, 421, 450, 500, 501, 502, 503, 530, 0};
+ static const int rnto_codes[] = {250, 421, 500, 501, 502, 503, 530, 532, 553, 0};
+ int ret;
+
+ if ((ret = ftp_connect(h_src, h_src->filename)) < 0)
+ goto cleanup;
+
+ snprintf(command, sizeof(command), "RNFR %s\r\n", s->path);
+ if (ftp_send_command(s, command, rnfr_codes, NULL) != 350) {
+ ret = AVERROR(EIO);
+ goto cleanup;
+ }
+
+ av_url_split(0, 0, 0, 0, 0, 0, 0,
+ path, sizeof(path),
+ h_dst->filename);
+ snprintf(command, sizeof(command), "RNTO %s\r\n", path);
+ if (ftp_send_command(s, command, rnto_codes, NULL) == 250)
+ ret = 0;
+ else
+ ret = AVERROR(EIO);
+
+cleanup:
+ ftp_close(h_src);
+ return ret;
+}
+
URLProtocol ff_ftp_protocol = {
.name = "ftp",
.url_open = ftp_open,
@@ -1052,5 +1111,7 @@ URLProtocol ff_ftp_protocol = {
.url_open_dir = ftp_open_dir,
.url_read_dir = ftp_read_dir,
.url_close_dir = ftp_close_dir,
+ .url_delete = ftp_delete,
+ .url_move = ftp_move,
.flags = URL_PROTOCOL_FLAG_NETWORK,
};