-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle Pathname in download/upload #102
base: master
Are you sure you want to change the base?
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::Download
andUpload
try to know local/remote path is an IO or not usingrespond_to?(:write)
.But
Pathname#write
exists.Therefore, passing
Pathname
object 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#write
opens file without binary flag (external encoding is UTF-8), andIO#write
trys to convert data to UTF-8.When uploading
fails with: