net-ssh / net-scp

Pure Ruby implementation of the SCP protocol
http://github.com/delano/net-scp
MIT License
154 stars 63 forks source link

Passing in a Pathname object as local for download! fails #29

Open ezekg opened 8 years ago

ezekg commented 8 years ago

I'm assuming the Pathname object implements the write method, so this error is mistakenly thrown. Casting the Pathname object to a string fixes the issue, but this was rather hard to debug since the error message was about using an in-memory buffer.

To reproduce,

download! "some/path", Pathname.new("/some/other/path").parent, {
  recursive: true
}

To fix,

download! "some/path", Pathname.new("/some/other/path").parent.to_s, {
  recursive: true
}

What if we automatically perform a to_s on Pathname objects to catch this?

ezekg commented 8 years ago

For reference, here's an issue that was reported to me with a stack trace: https://github.com/ezekg/theme-juice-cli/issues/73

zetetic commented 7 years ago

Similar behavior occurs for upload! -- passing a Pathname object as the 'remote' argument raises an exception when the channel is closed. Converting the 'remote' to a string does not raise an exception -- in both cases the upload itself succeeds.

mfazekas commented 7 years ago

I think instead of write we could check for is_a?(StringIO) i don't see it docmented that user can passin anything that accepts a write