pkg / sftp

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

Permission issue writing #454

Closed xbassols closed 3 years ago

xbassols commented 3 years ago

Hello,

I've been trying to find a permission issue that I'm having when writing via SFTP using the client. Reading is fine and writing via terminal too (using sftp and put) but when using the library I'm having a permission problem. I've tried with OpenFile trying different flags and with Create with no luck always returning permission denied as error (on the Create or OpenFile instruction).

Can you throw some light to the issue? What should I test next?

Thanks!

puellanivis commented 3 years ago

Do you have any error messages available? and/or some example code that isn’t working?

xbassols commented 3 years ago

The only error I get is permission denied when executing

w, err := client.Create(remoteFilePath) or client.OpenFile(remoteFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC)

No other error whatsoever. It's worth noting that it does work via sftp terminal client (MacOS) and via ssh2-sftp-client on NodeJS.

Reading works just fine.

puellanivis commented 3 years ago

Could you copy paste the whole error from the err.Error()?

Also, what is the form of your remoteFilePath? Know that it has to be an absolute path, there is no support for a relative path.

xbassols commented 3 years ago

The error is only permission denied no matter how you print it. Even inspecting it with the debugger. And the path should be ok since I can list the folder content.

xbassols commented 3 years ago

Alright happy to report that I've found the issue.

It looks like that either the naming of the file is too long (45 char) or there is some kind of glitch when using a file with a name like FILE-2006-01-02T15:04:05Z.txt on this server. I've shortened the file name to FILE-20060102150405.txt and now its writing properly.

Hopefully that helps someone in the future.