pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.52k stars 380 forks source link

Issues with client.ReadDir #351

Closed bacicrajko closed 3 years ago

bacicrajko commented 4 years ago

Hi, I am not sure if this is a problem with library or in my code. When I open a sftp connection current directory is set as /home/myuser Passing path to client read dir does not return any results. client.ReadDir("/var/logs/node1") does not return any files. Only directory that I can read is the one I am currently in (/home/myuser)

drakkan commented 4 years ago

Hi, client.ReadDir returns []os.FileInfo, error can you please check the error? If not nil it could contain useful information (maybe a permission issue in your case)

puellanivis commented 4 years ago

Indeed, it’s not uncommon for /var/logs/* to be root only read:

drwx------ 1 root   root       368 11. Apr 13:13 YaST2

In this case, attempting to ReadDir from that directory would result in a permission denied result for any user other than root.

bacicrajko commented 4 years ago

@drakkan @puellanivis thank you for your responses. The error I'm getting is always: file does not exist

However based on your comments I tried with a different user and now I can list the directory, but its rather strange that I didnt get different error

eikenb commented 4 years ago

@bacicrajko .. The error returned is up the the SFTP server. It might be returning file not found as a security feature, so you can't look for files on the system by checking for permission issues.

drakkan commented 3 years ago

If the issue still persist, please reopen providing more info and a way to reproduce, thank you