GithubHelp home page GithubHelp logo

Comments (7)

huashengdun avatar huashengdun commented on August 28, 2024

如果你的ssh服务器默认编码utf-8 (Linux系统一般都默认使用这个编码),
而你使用vim处理gbk编码的中文文件, 简单的方法就是,

打开gbk文件

$ vim gbk.txt

使用编码gbk

:e ++enc=gbk

from webssh.

anythingwhat avatar anythingwhat commented on August 28, 2024

@huashengdun
多谢。实际我是先找到了https://github.com/xsank/webssh.git, 后来发现这个project不支持中文非utf-8编码,和这个问题类似 xsank/webssh#10. 如果ssh服务器上有一个文件名是中文gbk编码的文件,通过webssh终端登录这个服务器的时候,终端会报connection close, 查看具体报错信息为“could not decode a text frame as utf-8”。能不能指导下https://github.com/xsank/webssh.git 这个project如何修改可以解决这个问题,非常感谢

from webssh.

huashengdun avatar huashengdun commented on August 28, 2024

不好意思,我对xsank/webssh这个项目不熟悉。
你应该找这个项目的作者xsank寻求帮助。

from webssh.

huashengdun avatar huashengdun commented on August 28, 2024

@anythingwhat
如果ssh服务器上有一个文件名是中文gbk编码的文件,通过webssh终端登录这个服务器的时候,终端会报connection close, 查看具体报错信息为“could not decode a text frame as utf-8”。
服务器上存有中文gbk编码的文件,登录服务器不会导致“终端会报connection close”。
导致客户端wesocket断开,是因为你在terminal运行了类似cat之类的查看命令。

服务端解决方法如下:

cat gbk.txt | iconv -f gbk -t utf-8

在我的这个应用中,在js里有了两个函数,wssh.set_encoding(encoding), wssh.reset_encoding()。

客户端解决方法如下:

1.设置客户端使用gbk编码,在console中运行,

wssh.set_encoding('gbk');
  1. 然后你可以在客户端terminal中可直接运行,能正确显示gbk文件
cat gbk.txt
  1. 恢复使用服务器的默认编码,在console中运行,
wssh.reset_encoding();

from webssh.

anythingwhat avatar anythingwhat commented on August 28, 2024

@huashengdun ,非常感谢

from webssh.

anythingwhat avatar anythingwhat commented on August 28, 2024

@huashengdun 再请教下。能不能在程序里自动处理、支持查看gbk编码的中文文件,这样显式的用cat gbk.txt | iconv -f gbk -t utf-8或者wssh.set_encoding不方便

from webssh.

huashengdun avatar huashengdun commented on August 28, 2024

可以先对文件检测编码,然后使用检测获的编码对文件读取成文本文件。
对每个文件都这样做,估计会影响后台效率,尤其大文件。
然后最终程序还要把你的文件文件用用utf-8编码,最后网络传输。

from webssh.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.