From cc1b44567b77dda34203f0fcddeecc2d093a2480 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 17 Dec 2023 03:11:46 +0700 Subject: ssh/sftp: fix Stat on empty remote file name The implementation of SSH server for Stat is not consistent with the RFC. The RFC mentioned that An empty path name is valid, and it refers to the user's default directory (usually the user's home directory). But this only working on some command, like Mkdir, but not Stat. --- lib/ssh/sftp/client.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/ssh') diff --git a/lib/ssh/sftp/client.go b/lib/ssh/sftp/client.go index 215bf406..47364f4f 100644 --- a/lib/ssh/sftp/client.go +++ b/lib/ssh/sftp/client.go @@ -580,7 +580,13 @@ func (cl *Client) Setstat(remoteFile string, fa *FileAttrs) (err error) { // Stat get the file attributes based on the remote file path. // This method follow symbolic links. +// +// To stat the user's home directory pass empty string or '.' in remoteFile +// parameter. func (cl *Client) Stat(remoteFile string) (fa *FileAttrs, err error) { + if remoteFile == `` { + remoteFile = `.` + } var ( logp = "Stat" req = cl.generatePacket() -- cgit v1.3