Hi!

Xu, Qiang (FXSGSC) wrote:
> > I'm sorry, but then I do not understand what the problem is.
> 
> For example, suppose I want to remove the folder "DOC.XSM": 
> =====================================================
> ./curl -v -u qxu:fair123 sftp://13.198.98.190/ -Q "rmdir 
> /home/qxu/scan/DOC.XSM"
> =====================================================
> It only works when the folder is not empty.

Now I understand. Thanks!

This example makes everything clear. It is very important to show
examples of what you are doing when there is a problem.

Also remember that this mailing list is for libssh2, so in order to
reach the curl experts it is better to post questions about curl to
the curl mailing list.


> Since curl just sends the quoted command to the sftp server,

But it doesn't.

As always, it is good to read the documentation to find out more
about the tools that you are using:

--8<-- man curl
       -Q/--quote <command>
..

SFTP  is  a  binary protocol. Unlike for FTP, libcurl interprets
SFTP quote commands before sending them to the server.   Follow‐
ing is the list of all supported SFTP quote commands:

..

rmdir directory
       The rmdir command removes the directory  entry  specified
       by the directory operand, provided it is empty.
-->8--


There is no such thing as sending a quoted command via SFTP.

SFTP is, as described in the draft and in the curl documentation, a
binary, packet based, protocol. It doesn't used text based commands
and responses like FTP.

curl uses libssh2 and transforms the text command above into an SFTP
request packet where the rmdir command is encoded as the
SSH_FXP_RMDIR request id and the directory you specify is encoded
as a string following it in the packet.


> it is probably the server that executes the command

The SFTP server parses the packet, and will normally execute the
unlink() system call on the specified path.


> (and fails).

Yes. Only empty directories can be removed.

If you want to delete a directory including all contents, you must
manually fetch the contents of that directory (using the SFTP
protocol) and recursively delete every file in every subdirectory.

If you can log in to the system and execute commands then you can use
that method instead of SFTP, and execute rm -rf. That is not
supported in curl, and I think that is wise.


> Now I am working with sftp server.

Which SFTP server? The one in OpenSSH?


> So is http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13
> enough for me? :-)

If you are working with the OpenSSH SFTP server then it is better to
use the documentation that applies to it.


But the answer to deleting files recursively can not be found in any
draft and it has nothing to do with quotes. There are only two
solutions as mentioned above;

1. Write your own SFTP client (e.g. using libssh2) which recurses
through all subdirectories and deletes everything before removing the
top level directory.

or

2. Execute rm -rf on the system, via SSH or some other way.


> > I'm sorry, I don't think I understand this. Can you explain 
> > what you mean by "quote commands" ?
> 
> Please refer to the above quoted command in curl expression.

Thanks for the clarification!


//Peter
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel

Reply via email to