Skip to content

sftp: Add new quote commands 'atime' and 'mtime' - #5810

Closed
COFFEETALES wants to merge 1 commit into
curl:masterfrom
COFFEETALES:sftp_atime_mtime
Closed

COFFEETALES wants to merge 1 commit into
curl:masterfrom
COFFEETALES:sftp_atime_mtime

Conversation

@COFFEETALES

Copy link
Copy Markdown

In some situations, you may have to change the modified or last accessed date of a specific file.
This PR add new quote commands for sftp only.

Comment thread lib/vssh/libssh.c Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two else if statements look very similar.
Why not try to put them into one and obfuscate the code a bit :-)

Comment thread docs/cmdline-opts/quote.d Resolved
@COFFEETALES
COFFEETALES requested a review from bagder August 16, 2020 04:33
@bagder bagder added the feature-window A merge of this requires an open feature window label Aug 16, 2020
@bagder

bagder commented Aug 24, 2020

Copy link
Copy Markdown
Member

Thanks!

@bagder bagder closed this in fab5185 Aug 24, 2020
@PayBas

PayBas commented May 1, 2023 •

Copy link
Copy Markdown

@COFFEETALES @bagder I've been trying for 2 days now to get this working with curl version 7.85.0, but no luck so far.
But I'm not sure whether this is bug, a config error on my part, or some missing documentation on https://curl.se/docs/manpage.html#-Q

Server:

# cat sshd_config.d/sftp.conf 
Subsystem sftp internal-sftp

Match User sftp
     ChrootDirectory /opt/sftp/
     X11Forwarding no
     AllowTCPForwarding no
     ForceCommand internal-sftp

# ls -al /opt/sftp/
drwxr-xr-x. 3 root root 4096 Apr 27 01:16 .
drwxr-xr-x. 7 root root 4096 Apr 27 01:16 ..
drwxrwxrwx. 6 sftp sftp 4096 May  1 13:58 data

Client:

Working correctly:

$ curl -Q "mkdir data/foo" -u sftp:pass sftp://server.my.corp:22/data/
drwxrwxrwx    7 1010     1010         4096 May  1 12:16 .
drwxr-xr-x    3 root     root         4096 Apr 26 23:16 ..
drwxr-xr-x    4 1010     1010         4096 May  1 10:47 foo

$ curl -Q "rename data/foo data/bar" -u sftp:pass sftp://server.my.corp:22/data/
drwxrwxrwx    7 1010     1010         4096 May  1 12:16 .
drwxr-xr-x    3 root     root         4096 Apr 26 23:16 ..
drwxr-xr-x    4 1010     1010         4096 May  1 10:47 bar

$ curl -Q "ln data/foo data/bar" -u sftp:pass sftp://server.my.corp:22/data/
drwxrwxrwx    7 1010     1010         4096 May  1 12:16 .
drwxr-xr-x    3 root     root         4096 Apr 26 23:16 ..
drwxr-xr-x    4 1010     1010         4096 May  1 10:47 bar
lrwxrwxrwx    1 1010     1010         4096 May  1 10:58 foo -> data/bar

Problematic:

$ now=$(date '+%Y-%m-%d %H:%M:%S %z')
$ curl -Q "mtime $now data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) Attempt to get SFTP stats failed: 2

$ curl -Q "atime $now data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) Attempt to get SFTP stats failed: 2

Am I missing something? Are there server-side requirements? Verbose output doesn't provide any additional insights.

Looking through the server logs didn't show any clear causes. Or sshd is logging the error to some log unknown to me.

@dfandrich

dfandrich commented May 1, 2023 via email

Copy link
Copy Markdown
Contributor

@PayBas

PayBas commented May 1, 2023 •

Copy link
Copy Markdown

@dfandrich thanks for the reply. Are you actually getting successful results with that?

$ curl -Q "mtime $(date +%s) data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) incorrect date format for mtime

$ now=$(date +%s)
$ curl -Q "mtime $now data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) incorrect date format for mtime

$ curl -Q "mtime 1682955360 data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) incorrect date format for mtime

$ curl -Q "mtime '2023-05-01 17:41:16 +0200' data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) incorrect date format for mtime

$ now=$(date '+%Y-%m-%d %H:%M:%S %z')
$ curl -Q "mtime '$now' data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) incorrect date format for mtime

$ now=$(date '+%Y-%m-%d %H:%M:%S %z')
$ curl -Q "mtime $now data/bar" -u sftp:pass sftp://server.my.corp:22/data/
curl: (21) Attempt to get SFTP stats failed: 2

I should clarify that both the client and server are both Fedora 37 machines.
curl version: 7.85.0
OpenSSL version: OpenSSL 3.0.8 7 Feb 2023 (Library: OpenSSL 3.0.8 7 Feb 2023)

@dfandrich

dfandrich commented May 1, 2023 via email

Copy link
Copy Markdown
Contributor

@PayBas

PayBas commented May 1, 2023

Copy link
Copy Markdown

Wow. That's a very specific syntax. I wouldn't have thought of explicitly using escaped double-quotes.
Seems to be working now. Thanks a bunch @dfandrich 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-window A merge of this requires an open feature window SCP/SFTP

Development

Successfully merging this pull request may close these issues.

5 participants