Conversation
|
#33 seems to be same issue. |
235cd88 to
8d43a01
Compare
|
@Tietew thanks for the PR! I'm a bit concerned that adding a couple more A less intrusive change would be detecting Pathname-s and error-ing saying that Pathname-s are not supported, then it'll be the user's responsibility to call What do you think?! |
|
@mfazekas OMG! Thanks to pointing out. Another plan: check for index 8e7275e..fe2c317 100644
--- a/lib/net/sftp/operations/download.rb
+++ b/lib/net/sftp/operations/download.rb
@@ -311,7 +311,14 @@ module Net; module SFTP; module Operations
raise StatusException.new(response, "open #{entry.remote}") unless resp
onse.ok?
entry.handle = response[:handle]
- entry.sink = entry.local.respond_to?(:write) ? entry.local : ::File.open(entry.local, "wb")
+ entry.sink =
+ if entry.local.respond_to?(:open)
+ entry.local.open("wb")
+ elsif entry.local.respond_to?(:write)
+ entry.local
+ else
+ ::File.open(entry.local, "wb")
+ end
entry.offset = 0
download_next_chunk(entry)cf. https://ruby-doc.org/stdlib-2.7.0/libdoc/pathname/rdoc/Pathname.html#method-i-open Choices:
|
|
I found Following code will crash: tmp = Tempfile.new
sftp.download!('/path/to/remote', tmp)
# => ArgumentError: wrong number of arguments (given 1, expected 0)Is No.2 the best solution? |
|
I asked ruby-list ML this issue. |
|
@Tietew sorry for the late answer, yes let's go with 2.) that sound the least intrusive. |
|
Hi 👋🏾 ! I recently ran into an error when passing a
|
Net::SFTP::Operations::DownloadandUploadtry to know local/remote path is an IO or not usingrespond_to?(:write).But
Pathname#writeexists.Therefore, passing
Pathnameobject to downloading/uploading causes confusing exception.This PR convert pathnames to string using
#to_path.When downloading
fails with: (message depends on file content)
Because
Pathname#writeopens file without binary flag (external encoding is UTF-8), andIO#writetrys to convert data to UTF-8.When uploading
fails with: