File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,10 @@ type Client struct {
167
167
// already exists. If successful, methods on the returned File can be used for
168
168
// I/O; the associated file descriptor has mode O_RDWR. If you need more
169
169
// control over the flags/mode used to open the file see client.OpenFile.
170
+ //
171
+ // Note that some SFTP servers (eg. AWS Transfer) do not support opening files
172
+ // read/write at the same time. For those services you will need to use
173
+ // `client.OpenFile(os.O_WRONLY|os.O_CREATE|os.O_TRUNC)`.
170
174
func (c * Client ) Create (path string ) (* File , error ) {
171
175
return c .open (path , flags (os .O_RDWR | os .O_CREATE | os .O_TRUNC ))
172
176
}
Original file line number Diff line number Diff line change @@ -219,4 +219,11 @@ type StatusError struct {
219
219
msg , lang string
220
220
}
221
221
222
- func (s * StatusError ) Error () string { return fmt .Sprintf ("sftp: %q (%v)" , s .msg , fx (s .Code )) }
222
+ func (s * StatusError ) Error () string {
223
+ return fmt .Sprintf ("sftp: %q (%v)" , s .msg , fx (s .Code ))
224
+ }
225
+
226
+ // FxCode returns the error code typed to match against the exported codes
227
+ func (s * StatusError ) FxCode () fxerr {
228
+ return fxerr (s .Code )
229
+ }
Original file line number Diff line number Diff line change
1
+ package sftp
2
+
3
+ import (
4
+ "io"
5
+ "syscall"
6
+ "testing"
7
+
8
+ "github.com/pkg/errors"
9
+ "github.com/stretchr/testify/assert"
10
+ )
11
+
12
+ func TestErrFxCode (t * testing.T ) {
13
+ ider := sshFxpStatusPacket {ID : 1 }
14
+ table := []struct {
15
+ err error
16
+ fx fxerr
17
+ }{
18
+ {err : errors .New ("random error" ), fx : ErrSSHFxFailure },
19
+ {err : syscall .EBADF , fx : ErrSSHFxFailure },
20
+ {err : syscall .ENOENT , fx : ErrSSHFxNoSuchFile },
21
+ {err : syscall .EPERM , fx : ErrSSHFxPermissionDenied },
22
+ {err : io .EOF , fx : ErrSSHFxEOF },
23
+ }
24
+ for _ , tt := range table {
25
+ statusErr := statusFromError (ider , tt .err ).StatusError
26
+ assert .Equal (t , statusErr .FxCode (), tt .fx )
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments