Linux FTP上传中文结尾的文件乱码

Z小繁 某差旅公司 中台&开放平台&研发总监&伪产品  2016-01-19 08:45:14
搭了个FTP服务器,用的是vsftpd。

系统版本:CentOS release 6.6 (Final),Linux version 2.6.32-504.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014

有个bug:如果直接上传中文结尾的文件,会出现乱码,比如上传《MySQL+索引最佳实践.pdf》,服务器上的文件会变为(文件名的小数点都没有了),不是由于编码问题,或是所谓的在浏览器打开就OK。

暂时解决方案:

①下载乱码文件手动更改其后缀(.pdf、.jpg等),部分可以正常访问;

②或者从服务器的图形化界面上传(这里我已经设置好了,选择ASCii上传即OK)。

③【推荐】上传中文文件时,在文件名末尾加【英文字符】即可。如上传《MySQL+索引最佳实践q.pdf》就一切正常。

有木有哪位大神知道如何解决这个问题啊!可以直接从windows的资源管理器上传额。第一次发帖,拜谢各位啦。
...全文
1239 12 点赞 打赏 收藏 举报
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
柳林风 2017-03-08
我也遇见这个问题了,请问楼主解决这个问题没有
  • 打赏
  • 举报
回复
Z小繁 2016-01-23
结贴啦,虽然最后没解决问题,还是谢谢各位。
  • 打赏
  • 举报
回复
Z小繁 2016-01-20
引用 9 楼 r_Jimy 的回复:
你找下相关软件用ext4格式化下U盘,从U盘里上传FTP,道理一样的
公司电脑禁用了usb接口,这条路实在行不通额
  • 打赏
  • 举报
回复
常书 2016-01-20
你找下相关软件用ext4格式化下U盘,从U盘里上传FTP,道理一样的
  • 打赏
  • 举报
回复
Z小繁 2016-01-19
核心即是: anonymous_enable=YES local_enable=YES write_enable=YES local_umask=022 anon_upload_enable=YES anon_mkdir_write_enable=YES dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES ascii_upload_enable=YES ascii_download_enable=YES chroot_local_user=YES chroot_list_enable=YES listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES anon_other_write_enable=YES anon_world_readable_only=no 先行谢过啦
  • 打赏
  • 举报
回复
Z小繁 2016-01-19
VSFTPD.conf配置文件如下: # Example config file /etc/vsftpd/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. # # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=YES # # Uncomment this to allow local users to log in. local_enable=YES # # Uncomment this to enable any form of FTP write command. write_enable=YES # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) local_umask=022 # # Uncomment this to allow the anonymous FTP user to upload files. This only # has an effect if the above global write enable is activated. Also, you will # obviously need to create a directory writable by the FTP user. anon_upload_enable=YES # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. anon_mkdir_write_enable=YES # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # # The target log file can be vsftpd_log_file or xferlog_file. # This depends on setting xferlog_std_format parameter xferlog_enable=YES # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES # # If you want, you can arrange for uploaded anonymous files to be owned by # a different user. Note! Using "root" for uploaded files is not # recommended! #chown_uploads=YES #chown_username=whoever # # The name of log file when xferlog_enable=YES and xferlog_std_format=YES # WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log #xferlog_file=/var/log/xferlog # # Switches between logging into vsftpd_log_file and xferlog_file files. # NO writes to vsftpd_log_file, YES to xferlog_file xferlog_std_format=YES # # You may change the default value for timing out an idle session. #idle_session_timeout=600 # # You may change the default value for timing out a data connection. #data_connection_timeout=120 # # It is recommended that you define on your system a unique user which the # ftp server can use as a totally isolated and unprivileged user. #nopriv_user=ftpsecure # # Enable this and the server will recognise asynchronous ABOR requests. Not # recommended for security (the code is non-trivial). Not enabling it, # however, may confuse older FTP clients. #async_abor_enable=YES # # By default the server will pretend to allow ASCII mode but in fact ignore # the request. Turn on the below options to have the server actually do ASCII # mangling on files when in ASCII mode. # Beware that on some FTP servers, ASCII support allows a denial of service # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd # predicted this attack and has always been safe, reporting the size of the # raw file. # ASCII mangling is a horrible feature of the protocol. ascii_upload_enable=YES ascii_download_enable=YES # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. # # You may specify a file of disallowed anonymous e-mail addresses. Apparently # useful for combatting certain DoS attacks. #deny_email_enable=YES # (default follows) #banned_email_file=/etc/vsftpd/banned_emails # # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). chroot_local_user=YES chroot_list_enable=YES # (default follows) #chroot_list_file=/etc/vsftpd/chroot_list # # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume # the presence of the "-R" option, so there is a strong case for enabling it. #ls_recurse_enable=YES # # When "listen" directive is enabled, vsftpd runs in standalone mode and # listens on IPv4 sockets. This directive cannot be used in conjunction # with the listen_ipv6 directive. listen=YES # # This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6 # sockets, you must run two copies of vsftpd with two configuration files. # Make sure, that one of the listen options is commented !! #listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES anon_other_write_enable=YES anon_world_readable_only=no
  • 打赏
  • 举报
回复
Z小繁 2016-01-19
引用 6 楼 r_Jimy 的回复:
猜测会不会跟分区格式有关,你试试在LINUX下用SAMBA共享个文件夹出来,上传上面的文件试试? windows下的话,换几个分区格式看看,另外建议抓包看看是不是包里头的名字已经被改了
尝试着使用SAMBA(参照:http://os.51cto.com/art/201506/478383.htm),执行sudo semanage fcontext -a -t samba_share_t "<directory>(/.*)?" 时报错 SELinux: Could not downgrade policy file /etc/selinux/targeted/policy/policy.24, searching for an older version. SELinux: Could not open policy file <= /etc/selinux/targeted/policy/policy.24: No such file or directory libsemanage.semanage_reload_policy: load_policy returned error code 2. SELinux: Could not downgrade policy file /etc/selinux/targeted/policy/policy.24, searching for an older version. SELinux: Could not open policy file <= /etc/selinux/targeted/policy/policy.24: No such file or directory libsemanage.semanage_reload_policy: load_policy returned error code 2. /usr/sbin/semanage: 无法提交 semanage 交易 百度google了,暂时还没解决这个问题,本人linux小白,大神可知何解。
  • 打赏
  • 举报
回复
Z小繁 2016-01-19
引用 5 楼 baijiaheizhiganmao 的回复:
你的程序中必须统一编码格式。在你传送文件的时候格式也必须一样。 你可以看看你上传的文件,他转化为数据流之后他的编码是什么。没准服务器那边自动转换了。
额(⊙o⊙)…没有代码,是直接在linux服务器上敲命令搭建的FTP服务器(如192.168.1.110/pub),然后从windows资源管理器拖文件到目录92.168.1.110/pub。还是谢谢。
  • 打赏
  • 举报
回复
常书 2016-01-19
猜测会不会跟分区格式有关,你试试在LINUX下用SAMBA共享个文件夹出来,上传上面的文件试试? windows下的话,换几个分区格式看看,另外建议抓包看看是不是包里头的名字已经被改了
  • 打赏
  • 举报
回复
忘世麒麟 2016-01-19
你的程序中必须统一编码格式。在你传送文件的时候格式也必须一样。 你可以看看你上传的文件,他转化为数据流之后他的编码是什么。没准服务器那边自动转换了。
  • 打赏
  • 举报
回复
Z小繁 2016-01-19
引用 3 楼 fan63182830 的回复:
/etc/sysconfig/i18n LANG="zh_CN.utf8"
这个试过了,没用的。原因现在基本确定,windows和linux的编码格式不同(ASCII方式上传文件是正常的)。还是非常感谢。
  • 打赏
  • 举报
回复
皇御雷霆 2016-01-19
/etc/sysconfig/i18n LANG="zh_CN.utf8"
  • 打赏
  • 举报
回复
相关推荐
发帖
Linux/Unix社区
加入

1.8w+

社区成员

Linux/Unix社区 专题技术讨论区
申请成为版主
帖子事件
创建了帖子
2016-01-19 08:45
社区公告
暂无公告