CURL Command Line Tool - Delete File from FTP Server

I am trying to use CURL to perform some operations on an ftp server in C ++ using Visual Studio. I do not need to do some downloads or downloads using the command line tools.

But to delete some file I have some errors.

Here is the command I'm typing:

 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' 

In addition, the file is on the server, so I do not understand.

+5
source share
3 answers

The problem is solved!

It seems that one quote does not work like this:

  curl -v -u username:pwd ftp://host/FileTodelete.xml -Q "DELE FileTodelete.xml" 
+9
source

You place the command with -Q , but -DELE file not a common ftp command. Try one of them:

 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' 
+5
source

I accomplished this task by first logging into my FTP server, then typing "?" on the command line to get a list of commands recognized by my FTP server. The command recognized by my server was "delete".

So, -Q "remove $ fileToRemove" $ serverURL

I also managed to get it working using -X "DELE $ fileToRemove" $ serverURL. However, I kept getting rc = 19 (because, in my opinion, the “-X” option mostly applies to HTTP | HTTPS?) From curl when I used this argument, even if the file was successfully deleted.

Not sure if other FTP servers recognize different commands, but this is what worked for me.

+2
source

Source: https://habr.com/ru/post/1214171/


All Articles