cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: SFTP / SCP send resume and preserve file attributes

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sun, 21 Feb 2010 14:56:41 +0100 (CET)

On Sun, 21 Feb 2010, Don Filippo wrote:

> I have got few questions. Firstly, I wanted to know is there any possibility
> to preserve file attributes (principally creation time and modification
> time) when sending file to remote server using SCP or SFTP?

To "preserve" them, it would mean that it would have to set them explictly on
the server (after the transfer) to what they were on the client, assuming the
info exists (which I believe depends on OS and underlying filesystem).

But no, libcurl does not offer that functionality. The libssh2 lib, that
libcurl uses for SCP and SFTP, can actually set the atime and mtime of a
(SFTP) file if I read things right, but libcurl doesn't really expose that
functionality.

> Also, I wrote setup in my application using libcurl to make resume sending.
> It works OK for SFTP, but it's not working, when I change protocol in
> CURLOPT_URL from sftp:// to scp:// :(

Right. SCP is a rather crude "hack" and it can't do much fanciness, so
resuming is actually not supported. I think a decent thing for libcurl to do
is to actually return an error if you try to resume a transfer with SCP. You
feel like working on a patch for it?

> Furthermore, I noticed that libcurl behaves strange with SCP and
> CURLOPT_APPEND. When CURLOPT_APPEND is set to 0 (owerwrite) using SFTP, I
> observed, that size of remote file increases starting from 0 bytes - it
> looks ok. But when I'm using SCP, size of remote file doesn't look to
> "restart" to 0, but at the beginning it has size like it had before (for
> example: after previously sending) and after some time it starts to
> increase.

As SCP doesn't really support resume as a concept in the "protocol" [*] I
don't think we should even try to understand what happens when you try to do
funny things with it. I would expect that a SCP upload to a file that already
exists will simply unconditionally overwrite the target from the beginning,
but I don't think there is or will ever be any guarantees for that.

[*] = I use the work protocol within quotes because while SSH is a properly
       speced protocol, SCP is just about invoking the same command on both
       sides of the connection and sending raw data between them. Those
       commands are not specified anywhere in any standard etc and there's no
       defacto way for things like resuming either.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-02-21