Commit Graph

121 Commits

Author SHA1 Message Date
John Eikenberry 0159c83e42 mention OpenFile as option to Create
Fixes #227
2018-02-06 14:03:47 -08:00
Paul c2bca6d357
Merge pull request #1 from pkg/master
Update from pkg/sftp
2017-12-20 15:29:39 +01:00
John Eikenberry f6ec992e48 expand docs on InternalInconsistency
Fixes #190

Add notes on possible causes and state of client object.
2017-11-04 12:48:40 -07:00
Iain Wade 9b6cdb8fab Add PosixRename method which uses the posix-rename@openssh.com extension
to support actual rename() operations rather than the link() call
effectively mandated by the sftp v3/draft-2 requirement that targets
not be overwritten.
2017-09-05 04:46:03 -07:00
John Eikenberry 22f089b9c4 Document internal inconsistency error 2017-07-25 21:04:32 -07:00
John Eikenberry babb028c61 Fix #189; add ClientOption type
Convert func(*Client)error places to use that type.

Did this mainly for consistency with ServerOption and improved
documentation.
2017-07-23 17:47:47 -07:00
John Eikenberry 08f9799191 Fix #185; add max packet size check and docs 2017-07-23 16:40:34 -07:00
John Eikenberry 737aa1dc61 Fixes #181: client deadlock on server death
The client was deadlocking if you killed the server when a file transfer
was occuring. The problem occured when you had many requests sent and
were waiting on responses when the server dies. The errors for all those
pending requests get sent along the response channel which is also used
for the errors reported by the new requests being made. The new request
channel send is in the same loop as the channel reading, so when it
blocked due to all other errors filling the channel it deadlocked the
program.

There were 2 possible fixes, changing the new request error channel
usage to be in a separate goroutine to keep it from blocking the loop or
to increase the size of the buffer to handle all the errors. This
implements the latter.

Included is a test that reproduces the problem most of the time. Due to
the required timing of the issue, it was impossible to reproduce 100% of
the time.
2017-06-29 11:27:52 -07:00
John Eikenberry 700027f436 drain inFlight packets in read/write methods
Fixes issue #167

File read/write client methods were breaking out of the packet handling
loops with packets still 'in flight' (packets sent without reply from
server) when errors occured. This caused problems after the fact with
the returning packets interfearing with later calls.

This change makes sure all the in flight packets are processed (even if
just discarded) before breaking out of the loop and returning.
2017-04-24 11:52:02 -07:00
John Eikenberry 027e3db83b handle all status packet results the same 2017-04-17 17:52:26 -07:00
unclejack 94df0a367c client,packet: remove redundant select & return
Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
2017-02-25 12:56:13 -08:00
John Eikenberry ff7e52ffd7 Fix deadlock issue in client Read and WriteTo
Same bug from ReadFrom and Write as referenced in ticket #145.
See a couple back for commit message with explanation.
2017-02-13 17:36:29 -08:00
John Eikenberry 15a2bdbeee Fix deadlock issue in client ReadFrom and Write
Fixes github issue #145

Increase the buffer of channel for dispatchRequest() responses to be
equal to the maximum possible difference between desiredInFlight minus
inFlight, as this is the maximum possible error returns it would get
before moving on to channel handling code.
2017-02-13 00:32:44 -08:00
Allan Feid dab2d69fc2 Make remove directory public 2017-02-05 15:08:02 -08:00
Andrew Kupasrimonkol 59640f4fcc Make SSH_FXP_STATUS "message" field optional.
Cisco SSH 2.0 server doesn't fill out the "message" field,
even though it returns valid status codes. This makes
File.Read method error out without actually reading the
file due to unmarshalStatus returning a "packet too short"
error.
2017-02-05 14:53:51 -08:00
Paul Komkoff b4b1d297a4 Fix hang on error in WriteTo.
When writer returns an error, the code would mess up inFlight counter
and the loop will never finish as the result.

We switch to only use inFlight to count requests to sftp server -
we delete from pendingWrites now so we can use len(pendingWrites) to
count.
2017-02-05 14:25:51 -08:00
Paul Komkoff caba5e8043 Fix memory leak in WriteTo.
When reassembling out-of-order responses, give Go a chance to
free blocks we already wrote.
2017-02-05 14:25:51 -08:00
John Eikenberry f37534d398 Fixes #83, documentation of File.Read()
Docs had it following semantics of os.File.Read when it was actually
adhering to io.Reader.Read semantics.
2017-01-13 19:58:21 -08:00
Carl Jackson 8197a2e580 client: satisfy go vet (#136) 2016-09-08 20:00:35 +10:00
Dave Cheney ea1a7bcdfc conn: seperate io.Reader and io.WriteCloser (#118)
Reading and Writing are less coupled in the sftp client and server than
they may be over a traditional ReadWriter. This mirrors the full duplex
/ half close nature of a TCP connection.

In essence conn.Reader cannot be closed locally, it can only close in
response to the remote side using conn.WriteCloser.Close(), or a network
error, which is effectively the same thing.

Make this behaviour super clear by no longer smooshing the type into a
ReadWriteCloser.
2016-06-15 20:19:51 +10:00
Dave Cheney 1a25dc501f rename sendRequest to sendPacket
clientConn.sendPacket now obscures clientConn.conn.sendPacket with a
diferent signature.
2016-06-15 18:57:05 +10:00
Dave Cheney 0847713e96 Migrate sendRequest to clientConn 2016-06-15 18:30:05 +10:00
Dave Cheney c91ab27c13 Move client.Close to clientConn.Close 2016-06-15 18:23:51 +10:00
Dave Cheney 9184483985 Introduce clientConn
clientConn embeds a conn and adds the basic loop/recv methods.
2016-06-15 18:08:04 +10:00
Dave Cheney a3218d2747 client: break out recv into loop and recv (#115)
This isolates the use of broadcastErr from the normal recv/lookup loop.
2016-06-15 17:58:19 +10:00
Dave Cheney 7d4fc94878 Introduce sftp.conn type to handle common send/recv behaviour (#113)
Introduce sftp.conn type to bind packet send/recv to a
io.ReadWriteCloser.
2016-06-15 11:50:02 +10:00
Dave Cheney 04d5f67e72 Small cleanups 2016-06-14 18:05:33 +10:00
akupas f4e06643a3 Make SSH_FXP_STATUS error message optional (#109)
Some SSH implementations do not include an error message in the
SSH_FXP_STATUS response causing an "index out of range" panic.
2016-06-14 12:24:38 +10:00
Dave Cheney 530345cb99 client: use a waitgroup rather than a close channel (#112) 2016-06-13 22:40:12 +10:00
Dave Cheney aca140bc99 Revert "Fix sendRequest"
This reverts commit 7500207056.
2016-06-13 21:37:38 +10:00
Dave Cheney 7500207056 Fix sendRequest
sendRequest was not returning a value to the channel if there was
_not_ an error. How did this even work ?!?

Also remove server_test.go because it was wrong, it was testing that
sending a properly formed, but invalid (ie, requested wrong extended
packet) packet would cause an error during send ... which is wrong.
sendRequest will only return an error if the client connection was
closed.
2016-06-13 21:29:13 +10:00
Dave Cheney 5e9ad277fc Use pkg/errors for error handling (#101) 2016-05-19 15:16:48 +10:00
Matt Layher 9374ae613d *: golint: add and fix up comments on exported types 2016-01-07 15:16:34 -05:00
Matt Layher b348482b1a *: golint (part 1) 2016-01-07 12:10:24 -05:00
Matt Layher 3fa7dab0f1 client: add normaliseError, make Client.{Lstat,Open,Stat} satisfy os.IsNotExist 2016-01-03 16:10:58 -05:00
Dave Cheney bd1c81068b Always pass buffered channel to Read/Write
Fixes #55

c.sendRequest always does the right thing, but a few fast paths were not
constructing a buffered channel which would cause c.dispatchRequest to
block on error.
2015-12-25 18:35:37 +01:00
xiu 00e2b63272 Merge branch 'master' into bugfix/35-cant-remove-directories-on-servu 2015-12-23 17:14:04 +01:00
Matthew Sykes f5afc8315a Add Getwd to client 2015-12-22 09:04:46 -05:00
Dave Cheney 167ae32ca7 Handle osx returning EPERM not ENOTDIR
Fixes #57

Also fix the integration tests to run on darwin by default.
2015-12-22 13:34:21 +09:00
xiu 2034fcb625 Support SSH_FX_FILE_IS_A_DIRECTORY while trying to remove a directory 2015-12-21 16:27:15 +01:00
Dave Cheney e09e01e6e1 Merge pull request #53 from boomlinde/missing-language-tag
make the StatusError language tag optional
2015-10-31 11:23:59 +11:00
Philip Linde e6dc896441 make the StatusError language tag optional 2015-10-27 12:16:11 +01:00
Josh Deprez d434a0c545 Add Name method to File
Similar to os.File's Name.
2015-09-25 17:55:20 +10:00
Mark Sheahan a6fc4b8c1f Add comments for *Client.Stat and *Client.Lstat 2015-09-07 23:04:52 -07:00
Mark Sheahan d80ae36051 rmdir and symlink packet handling 2015-09-07 01:05:16 -07:00
Mark Sheahan 7bb2083ca9 Address review comments; about to change decodePacket() 2015-09-06 23:55:15 -07:00
Mark Sheahan 0aec5ce5ec use merge-to target branches, not ScriptRock ones 2015-09-06 21:54:42 -07:00
Mark Sheahan 4325c3654b fix format of 'name' packets (shortname, longname, attrs), add Stat 2015-08-05 12:57:28 -07:00
Mark Sheahan 2f3ef8b897 Merge branch 'master' into server 2015-08-04 21:11:01 -07:00
Mark Sheahan 615df6108a Merge branch 'master' of https://github.com/pkg/sftp 2015-08-04 21:00:34 -07:00