sftp: Creating file on AWS SFTP managed services always get "Cannot open file in mode: WRITE|TRUNCATE|CREATE|READ" (SSH_FX_OP_UNSUPPORTED)
When using AWS SFTP managed services, sftp client always failed to create files. Create function (client.Create()
) always returned error with message “Cannot open file in mode: WRITE|TRUNCATE|CREATE|READ” (SSH_FX_OP_UNSUPPORTED).
This error only happened on AWS SFTP managed services. Regular SFTP server has no issue. The same endpoint were tested using sftp command, FileZilla and even .Net sftp library and all working normally. Only go sftp package were returned the error.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 22 (6 by maintainers)
Commits related to this issue
- Merge pull request #310 from pkg/issue-305-client-write Issue 305 client write Fixes #305 — committed to pkg/sftp by eikenb 5 years ago
Thanks for the investigation and thoughts @sugacube. I checked openssh’s sftp client and it behaves similarly. Opening a new file with either uses write/create/truncate or write/create/append. No read anywhere in the upload call.
@rama3i you can test this idea out by replacing your
client.Create(path)
call withclient.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC)
. This would replicate what winscp and openssh do opening the file for write only. If you get a chance to try this, please let me know if it helps.i’m a quite time constrained at the moment so difficult to dive deeply, but I had some thought about it. I could be totally wrong here but maybe worth a shot.
As aws sftp is s3 backed, maybe can’t support read/write connection at the same time. maybe client.Create() should only open for writing not for reading ? @rama3i maybe you could try to change that in the code and try to see if that would work? (e.g. in client.go function Create() change
os.O_RDWR
intoos.O_WRONLY
) ?I’m not sure how other sftp clients open for write - i tried looking around in the code of filezilla but could not immediately find relevant code. mabye @eikenb or someone else has looked around in the past in other clients maybe worth checking how this is done in other clients.
other thought I had was aws permissions, but that can’t be the reason as apparently other clients work.