问题
I have a remote embedded system and it is telnet-able. How can I fetch a binary file from it using ruby? If it were a text file, I could have used:
con = Net::Telnet::new("Host"=>ip,"Timeout"=>200) #Host not host
File.open("fetched_file","w+") do |f|
con.cmd("cat /ect/file") {|data| f.write(data)}
end
But this wouldn't work for binary file you won't get desirable data by cat
ing it.
回答1:
establish your telnet connection then
send the command:
uuencode filename -
to the remote host, replacing filename with the filename
take the data you are sent and pass it to uudecode
on your system
回答2:
If the device has uuencode
installed, you could use that to 'wrap' the binary into printable characters. Other possibility is to run dd if=/etc/file 2>/dev/null
to dump the data (however I am not completely certain this will word any better...)
来源:https://stackoverflow.com/questions/2062834/how-to-fetch-a-binary-file-from-a-remote-embeded-system-using-telnet