cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Wanted: cURL example for ftp get directory over SSH

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 5 Aug 2011 00:12:15 +0200 (CEST)

On Thu, 4 Aug 2011, Phill Lowe wrote:

> I use cURL to automate connections to HTTPS servers many times a day. It is
> a lifesaver!

Thanks for the praise!

> I would like to replace psftp with cURL for our connections to a couple of
> SSH type servers. The syntax for connecting is clear from the manual. I
> don't understand how I would get a directory listing so I would know what
> files to download or how I can delete a file once it has been downloaded.
> An example would help tremendously! Thanks!

Let me try. First off, curl doesn't really speak "SSH". It speaks SCP and
SFTP, which both are using SSH but are two different protocols on top of SSH.
(Well, calling SCP a separate protocol might be a bit of a stretch but let's
call it that now for simplicity.)

With SCP, curl can't list directories at all since all it then can do is copy
files back and forth.

With SFTP, curl _can_ list directories and then you do it by making sure the
URL ends with a trailing slash: "sftp://example.com/list/this/dir/"

With SFTP, curl can also be made to send "quote" commands using -Q. That's a
list of custom commands you can make curl run before or after the specified
transfer. curl then accepts ten different commands (see the man page for
details) and to delete a specific file after a transfer, you'd do something
like:

  curl -Q "-rm file" sftp://example.com/file"

As always, it may help to use -v to figure out what curl does.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2011-08-05