I'm actually trying to use CURL
to make some operations on a ftp server in C++ with Visual Studio. I've no trouble to do some uploads or downloads with commande line tools.
But for deleting some file I have some errors.
Here is the command I type:
curl -v -u username:pwd ftp://host/FileTodelete.xml -Q '-DELE FileTodelete.xml'
This is the answer:
* Adding handle: conn: 0x1ca5260
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x1ca5260) send_pipe: 1, recv_pipe: 0
* About to connect() to host port 21 (
* Trying ......
* Connected to host (...) po
< 220-FileZilla Server version 0.9.49 beta
< 220 Bienvenue sur le serveur FTP de HandTrainer
> USER username
< 331 Password required for username
> PASS pwd
< 230 Logged on
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> '-DELE
* ftp_perform ends with SECONDARY: 0
< 500 Syntax error, command unrecognized.
* QUOT command failed with 500
* Closing connection 0
curl: (21) QUOT command failed with 500
* Rebuilt URL to: FileTodelete.xml'/
* Adding handle: conn: 0x1ca5260
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 1 (0x1ca5260) send_pipe: 1, recv_pipe: 0
* Could not resolve host: FileTodelete.xml'
* Closing connection 1
curl: (6) Could not resolve host: FileTodelete.xml'
Moreover, the file is on the server so I don't understand.
To make a DELETE request using Curl, you need to use the -X DELETE command-line option followed by the target URL. To pass additional headers to the HTTP server, use the -H command-line option. The "Accept: application/json" header tells the server that the client expects JSON data in response.
DESCRIPTION. curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, GOPHER, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction.
To delete files on the FTP server use the delete command. To delete several files at once, use the mdelete command. You will be asked to provide a “y” or “n” confirmation for the deletion of each file. Here our FTP user has listed the files to see their names and then chosen one to delete.
Problem solved! The dash before DELE
should not be there:
curl -v -u username:pwd ftp://host/FileTodelete.xml -Q "DELE FileTodelete.xml"
You place a command with -Q
, but -DELE file
is not a common ftp command. Try one of these instead:
curl -v -u username:pwd ftp://host/FileTodelete.xml -Q 'DELE FileTodelete.xml'
curl -v -u username:pwd ftp://host/FileTodelete.xml -Q 'DELETE FileTodelete.xml'
curl -v -u username:pwd ftp://host/FileTodelete.xml -Q 'rm FileTodelete.xml'
I accomplished this task by first logging into my FTP server then typing "?" at the command line to get a list of commands recognized by my FTP server. The command recognized by my server was "delete".
So, -Q"delete $fileToRemove" $serverURL
I was also able to get it to work by using -X"DELE $fileToRemove" $serverURL. However, I kept getting rc=19 (because I think the "-X" option mostly applies to HTTP|HTTPS?) from curl when I used this argument even though the file was successfully deleted.
Not sure if other FTP servers recognize different commands but this is what worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With