Properly handle io.EOF error conditions when reading

Previously, the Server.Serve method would never return nil,
because the infinite for-loop handling request packets would
only break if reading a packet reported an error.
A common termination condition is when the underlying connection
is closed and recvPacket returns io.EOF.
In which case Serve should ignore io.EOF and
treat it as a normal shutdown.

However, this means that recvPacket must correctly handle io.EOF
such that it never reports io.EOF if a packet is partially read.
There are two calls to io.ReadFull in recvPacket.
The first call correctly forwards an io.EOF error
if no additional bytes of the next packet are read.
However, the second call incorrectly forwards io.EOF
when no bytes of the payload could be read.
This is incorrect since we already read the length and
should convert the io.EOF into an io.ErrUnexpectedEOF.
3 files changed
tree: 13f8a5993abbd01665b76384c81a1ea9fe8b8993
  1. .github/
  2. examples/
  3. internal/
  4. server_standalone/
  5. .gitignore
  6. allocator.go
  7. allocator_test.go
  8. attrs.go
  9. attrs_stubs.go
  10. attrs_test.go
  11. attrs_unix.go
  12. client.go
  13. client_integration_darwin_test.go
  14. client_integration_linux_test.go
  15. client_integration_test.go
  16. client_test.go
  17. conn.go
  18. CONTRIBUTORS
  19. debug.go
  20. example_test.go
  21. fuzz.go
  22. go.mod
  23. go.sum
  24. LICENSE
  25. ls_formatting.go
  26. ls_formatting_test.go
  27. ls_plan9.go
  28. ls_stub.go
  29. ls_unix.go
  30. Makefile
  31. match.go
  32. packet-manager.go
  33. packet-manager_test.go
  34. packet-typing.go
  35. packet.go
  36. packet_test.go
  37. pool.go
  38. README.md
  39. release.go
  40. request-attrs.go
  41. request-attrs_test.go
  42. request-errors.go
  43. request-example.go
  44. request-interfaces.go
  45. request-plan9.go
  46. request-readme.md
  47. request-server.go
  48. request-server_test.go
  49. request-unix.go
  50. request.go
  51. request_test.go
  52. request_windows.go
  53. server.go
  54. server_integration_test.go
  55. server_nowindows_test.go
  56. server_plan9.go
  57. server_statvfs_darwin.go
  58. server_statvfs_impl.go
  59. server_statvfs_linux.go
  60. server_statvfs_plan9.go
  61. server_statvfs_stubs.go
  62. server_test.go
  63. server_unix.go
  64. server_windows.go
  65. server_windows_test.go
  66. sftp.go
  67. sftp_test.go
  68. stat_plan9.go
  69. stat_posix.go
  70. syscall_fixed.go
  71. syscall_good.go
README.md

sftp

The sftp package provides support for file system operations on remote ssh servers using the SFTP subsystem. It also implements an SFTP server for serving files from the filesystem.

CI Status Go Reference

usage and examples

See https://pkg.go.dev/github.com/pkg/sftp for examples and usage.

The basic operation of the package mirrors the facilities of the os package.

The Walker interface for directory traversal is heavily inspired by Keith Rarick's fs package.

roadmap

  • There is way too much duplication in the Client methods. If there was an unmarshal(interface{}) method this would reduce a heap of the duplication.

contributing

We welcome pull requests, bug fixes and issue reports.

Before proposing a large change, first please discuss your change by raising an issue.

For API/code bugs, please include a small, self contained code example to reproduce the issue. For pull requests, remember test coverage.

We try to handle issues and pull requests with a 0 open philosophy. That means we will try to address the submission as soon as possible and will work toward a resolution. If progress can no longer be made (eg. unreproducible bug) or stops (eg. unresponsive submitter), we will close the bug.

Thanks.