I don't get why when I upload (ftp.put) a copy of the same file, then download that copy, ruby thinks the content is different? Obviously something in Net::FTP is screwing with my ISO-8859-1 character in the file? I dunno, still trying to track it down.
Created
September 17, 2012 14:17
-
-
Save tigris/3737579 to your computer and use it in GitHub Desktop.
Ruby Net::FTP screwing encoding?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> | |
</head> | |
<body> | |
<div id="main"> | |
<div title="Skötsel"> | |
<p>För mer information, se Natursten Skötsel Inomhus, utgiven av Sveriges Stenindustriförbund (SSF)</p> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default encoding: UTF-8 | |
default encoding valid?: true | |
forced encoding: ISO-8859-1 | |
forced encoding valid?: true | |
content same after force encode?: true | |
encoding after ftp actions: UTF-8 | |
encoding valid after ftp actions?: true | |
content match original after ftp actions?: false | |
content match original force encoded after ftp actions?: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/ftp' | |
Net::FTP.open('tigris.id.au', 'danial', 'xxxxxx') do |ftp| | |
ftp.binary = true | |
ftp.passive = true | |
ftp.get 'iso-8859-1.html' | |
content = File.read('iso-8859-1.html') | |
puts "default encoding: #{content.encoding}" | |
puts "default encoding valid?: #{content.valid_encoding?}" | |
forced_encoding = content.force_encoding('iso-8859-1') | |
puts "forced encoding: #{forced_encoding.encoding}" | |
puts "forced encoding valid?: #{forced_encoding.valid_encoding?}" | |
puts "content same after force encode?: #{content.to_s == forced_encoding.to_s}" | |
`cp iso-8859-1.html iso-8859-1_new.html` | |
ftp.put 'iso-8859-1_new.html' | |
sleep 1 | |
ftp.get 'iso-8859-1_new.html' | |
new_content = File.read('iso-8859-1_new.html') | |
puts "encoding after ftp actions: #{new_content.encoding}" | |
puts "encoding valid after ftp actions?: #{new_content.valid_encoding?}" | |
puts "content match original after ftp actions?: #{content.to_s == new_content.to_s}" | |
puts "content match original force encoded after ftp actions?: #{forced_encoding.to_s == new_content.to_s}" | |
`rm iso-8859-1.html` | |
`rm iso-8859-1_new.html` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same problem here 😢 have you made any progress on that issue?