How to resolve mixed character Encodings in ruby?

I’m learning ruby and try to get the filename from a ftp server. The
I got was encoded in gb2312(simplified Chinese), It’s success in most
cases with these codes:

str = str.force_encoding(“gb2312”)
str = str.encode(“utf-8”)

but it will make an error “in encode’: “\xFD” followed by “\x88” on
(Encoding::InvalidByteSequenceError)” if the string contains the symbol
or “【”.

Then I use


to detect if all filename strings were encoded by gb2312, some of them
return false. I think I must deal with a string list that’s in mixed
character encodings. Help me! Thank you!