Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed

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

wants to merge 1 commit into from

Conversation

COFFEETALES
Copy link

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.

return;
}
sshc->quote_attrs->flags |= SSH_FILEXFER_ACMODTIME;
}
Copy link
Contributor

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 :-)

docs/cmdline-opts/quote.d Outdated Show resolved Hide resolved
@bagder bagder added the feature-window A merge of this requires an open feature window label Aug 16, 2020
@bagder
Copy link
Member

bagder commented Aug 24, 2020

Thanks!

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

PayBas commented May 1, 2023

@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
Copy link
Contributor

dfandrich commented May 1, 2023 via email

@PayBas
Copy link

PayBas commented May 1, 2023

@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
Copy link
Contributor

dfandrich commented May 1, 2023 via email

@PayBas
Copy link

PayBas commented May 1, 2023

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.

None yet

5 participants