Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Net::SFTP Transfer Mode (Binary vs Text)

Is there a way using the Net::SFTP Library in Ruby (API Link) to set the Transfer Mode to Binary? I am unforunately on a windows system and am uploading a UTF-8 file to a Unix system. The ruby library apparently using Text as the default Transfer Mode and causing my encoding to get garbled with ANSI. If I can force Binary mode the UTF-8 should remain in tact.

Thanks

like image 472
wmarbut Avatar asked Sep 11 '25 23:09

wmarbut


1 Answers

I think I found a workaround.

Before, we were doing something like this:

sftp.file.open(filename) do |f|
  f.puts(data)
end

We changed this to use a StringIO object, like so:

require 'stringio'
io = StringIO.new(data)
sftp.upload!(io, filename)

Using the upload! method seems to respect the encoding as it just copies the bytes.

Hope that helps.

like image 97
user519054 Avatar answered Sep 13 '25 13:09

user519054