CURL 命令行工具 - 从 FTP 服务器删除文件

问题描述 投票:0回答:4

我实际上是在尝试使用

CURL
和 Visual Studio 在 C++ 中的 ftp 服务器上进行一些操作。我可以毫不费力地使用命令行工具进行一些上传或下载。

但是删除一些文件我有一些错误。

这是我输入的命令:

curl -v -u username:pwd ftp://host/FileTodelete.xml -Q '-DELE FileTodelete.xml'

这就是答案:

* 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'

另外,文件在服务器上,所以我不明白。

curl command-line ftp delete-file
4个回答
20
投票

问题解决了!

DELE
之前的破折号不应该在那里:

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

8
投票

您使用

-Q
放置命令,但
-DELE file
不是常见的ftp 命令。尝试其中之一:

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'

3
投票

我通过首先登录到我的 FTP 服务器然后输入“?”来完成这个任务。在命令行获取我的 FTP 服务器识别的命令列表。我的服务器识别的命令是“删除”。

所以,-Q"删除 $fileToRemove" $serverURL

我还可以通过使用 -X"DELE $fileToRemove" $serverURL 让它工作。但是,即使文件已成功删除,当我使用此参数时,我仍然从 curl 获得 rc=19(因为我认为“-X”选项主要适用于 HTTP|HTTPS?)。

不确定其他 FTP 服务器是否识别不同的命令,但这对我有用。


0
投票

附加信息,从非根目录中删除文件: 停留在 root 上并删除带有 -Q 命令路径的文件

curl ftp://192.168.140.XXXX:21 -Q 'DELE ISOS/foo.iso'
curl ftp://192.168.140.XXXX:21 -Q 'DELETE ISOS/foo.iso'
curl ftp://192.168.140.XXXX:21 -Q 'rm ISOS/foo.iso'
© www.soinside.com 2019 - 2024. All rights reserved.