Commit Graph

151 Commits

Author SHA1 Message Date
Cassondra Foesch 3c22ebff33
Merge pull request #385 from greatroar/list-extensions
New method Client.Extensions to list server extensions
2020-10-23 19:04:51 +00:00
greatroar d352a1d176 Add Client.Sync method
This uses the fsync@openssh.com extension:
https://github.com/openssh/openssh-portable/blob/master/PROTOCOL, §3.6.
2020-10-23 13:09:54 +02:00
greatroar 265b8168fd New method Client.Extensions to list server extensions 2020-10-23 11:16:44 +02:00
Nicola Murino 3177348ca5 pack structures so they have less size
This is a micro optimization, it fixes warnings like this one:

packet.go:707:24: struct of size 32 bytes could be of size 24 bytes
2020-09-08 10:18:15 +02:00
Nicola Murino b6bdd772b5 truncate should not change offset
improved Fsetstat test case
2020-08-25 07:46:42 +02:00
Nicola Murino a011842257 request server: add support for SSH_FXP_FSETSTAT
we need to add a case for this packet inside the packet worker otherwise
it will be handled in hasHandle case and it will become a "Put" request.

Client side if a Truncate request is called on the open file we should
send a FSETSTAT packet, the request is on the handle, and not a SETSTAT
packet that should be used for paths and not for handle.
2020-08-24 15:00:36 +02:00
Cassondra Foesch 4550e71d6e Add a mutex to protect f.offset in new File.Read 2020-08-19 11:09:42 +00:00
Cassondra Foesch 3ee8d0ba91
Merge pull request #285 from polygon-io/master
Add io.ReaderAt interface compatibility
2020-08-19 11:07:14 +00:00
Nicola Murino 1f178f9671 the allocator can now be enabled per request
Other minor changes as per review comments
2020-03-18 09:36:07 +01:00
Nicola Murino 3f969fcd59 add optional AllocationModeOptimized
after processing a packet we keep in memory the allocated slices and we reuse
them for new packets.
Slices are allocated in:

- recvPacket
- when we receive a sshFxpReadPacket (downloads)

The allocated slices have a fixed size = maxMsgLength.

Allocated slices are referenced to the request order id and are marked for reuse
after a request is served in maybeSendPackets.

The allocator is added to the packetManager struct and it is cleaned at the end
of the Serve() function.

This allocation mode is optional and disabled by default
2020-03-14 19:42:19 +01:00
Eran Sandler 77a4076c35 fixes based on comments + minor test added 2020-01-06 14:54:28 -08:00
Eran Sandler 09f03e7bff Added a ClientOption to determine whetehr to use Fstat or Stat when File.WriteTo is being called to support strange behaviour on some servers 2020-01-03 11:29:41 -08:00
John Eikenberry 8067637962 add note in Create() docs about AWS + O_RDWR 2019-10-13 19:18:30 -07:00
Nicola Murino b4ea0fd6f6 fix lint issues
These lint issues remain:

- request-errors.go, aliases for new error types
- request-attrs.go, UidGid. Changing this will break compatibility
2019-08-30 17:04:37 +02:00
Tommie Gannert 2c24eaad1c Implement the hardlink@openssh.com extension.
Both client and server. This is documented in

  https://github.com/openssh/openssh-portable/blob/master/PROTOCOL

Draft 7 of SFTP added support for SSH_FXP_LINK which supports both
symlinks and hardlinks, but unfortunately OpenSSH doesn't support
that:

  https://tools.ietf.org/html/draft-ietf-secsh-filexfer-07#section-7.7

Adding support for this as an option would be a nice extension to
this.
2019-08-25 20:16:37 -07:00
Nick Craig-Wood 48c87f62c9 Use Stat rather than Fstat in File.WriteTo to work around server bugs
Before this change in File.WriteTo() we used Fstat to discover the
length of the file being transferred.  It appears that some SFTP
servers do not implement this properly perhaps because it is a seldom
used call.

After this change we replace the Fstat on the file handle with a Stat
of the path.  Stat is commonly used function and implemented correctly
in both the servers that had the problem with Fstat, thus working
around the problem.

The code before and after uses the same number of SFTP roundtrips so
performance should be identical.

Fixes #288
2019-05-21 12:02:15 +01:00
Quinton Pike 00faa91b63 :| 2019-04-11 16:56:38 -04:00
Quinton Pike beae100160 Spacing 2019-04-11 16:46:08 -04:00
Quinton Pike a004247d1f Add io.ReaderAt interface compatibility
Read is now a proxy for ReadAt. Read uses the bytes read to set the new offset for the file, since ReadAt does not alter the offset.
2019-04-11 16:45:25 -04:00
Taizeng Wu 5cd7f324f9 Use channel to implement a simple way to wait 2018-12-05 16:30:09 +08:00
Taizeng Wu 3a53acc96b Reimplement Wait method to make it can be called concurrently from multiple goroutines 2018-12-05 14:47:03 +08:00
Taizeng Wu fbf9e05c66 Add Wait method to detect underlying SFTP connection closed
Closes #278
2018-12-03 17:46:45 +08:00
gm42 f9330fc78c Allow to configure maxConcurrentRequests 2018-05-28 09:44:19 +02:00
Nick Craig-Wood 0fc9a33d9a Document that ReadFrom/WriteTo are best for high throughput - fixes #158 2018-05-24 16:41:25 +01:00
Urjit Singh Bhatia 831654e4aa Client.MkdirAll - mimic os.MkdirAll code for consistency & perf 2018-04-25 08:13:19 -07:00
Urjit Singh Bhatia a03704e892 Add mkdirall implementation 2018-04-24 23:58:10 -07:00
John Eikenberry 49488377fa fix client deadlock on server death during writes
Fixes #234

Similar to #181 (which was about read methods), the client deadlocks on
server drop on write methods (Write/ReadFrom). This is another case of
broadcastErr() and dispatchRequest() deadlocking.

The fix is to bump up the channel used to communicate about inflight
packets to maxConcurrentRequests+1 (+1 is new). It seems that it can
have the full set of packets going and hit the error (triggering
broadcastErr) yet it still tries to call dispatchRequest again. More
details in that ticket.

I'm also bumping up the chan buffer in the read methods to keep them
consistent. I can't reproduce the problem, but it looks like it should
have it. So it might just be a much harder race to trigger.

This also includes 2 tests which reprocuded the issue for ReadFrom and
Write.
2018-03-15 13:53:30 -07:00
John Eikenberry 51703e3702
Merge pull request #220 from CodyDWJones/master
Expanded limits to the MaxPacket option.
2018-03-04 17:16:37 -08:00
Cody Jones f8a9ce48ad Allow the use of packets smaller than 32768 bytes, and add MaxPacketChecked/Unchecked client options to prevent developers from accidentally using larger, potentially incompatible sizes. 2018-02-22 14:05:13 -08:00
John Eikenberry 9fa3832aa2 update seek constants 2018-02-15 10:27:33 -08:00
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