ToB企服应用市场:ToB评测及商务社交产业平台

标题: 文件体系 FTP Ubuntu 安装入门介绍 [打印本页]

作者: 写过一篇    时间: 2024-8-3 15:51
标题: 文件体系 FTP Ubuntu 安装入门介绍
文件服务系列

文件存储服务体系(File Storage Service System)-00-文件服务器是什么?为什么需要?
文件存储服务体系(File Storage Service System)-01-常见的文件协议介绍
文件体系 FTP Ubuntu 安装入门介绍
文件存储服务体系(File Storage Service System)-02-SFTP 协议介绍
分布式文件服务体系(Distributed File System, DFS)-00-分布式文件服务体系是什么?
分布式存储体系-01-minio 入门介绍
分布式存储体系-02-开源的分布式文件体系 Fastdfs 安装入门介绍
分布式存储体系-03-ceph 一个可扩展的分布式存储体系介绍
分布式存储体系-04-GlusterFS 是一个基于对象的开源分布式文件体系,适用于云存储和媒体流等场景
分布式存储体系-05-Lustre 是一个高性能的分布式文件体系,重要用于大型超等盘算机集群
分布式存储体系-06-MooseFS 是一个开源的分布式文件体系,计划用于提供高可靠性和扩展性
分布式存储体系-07-OpenAFS 是 Andrew File System 的开源实现,是一个分布式网络文件体系
分布式存储体系-08-OrangeFS 是 PVFS 的下一代版本,是一个面向高性能盘算的开源并行文件体系
FTP

环境: Ubuntu 14.04
blog zh_CN
ubuntu14.04

  1. 全新安装:apt-get install vsftpd
  2. 重新安装:apt-get --reinstall install vsftpd
  3. 卸载并清除配置文件:apt-get --purge remove vsftpd
复制代码
  1. $   service vsftpd start
  2. $   service vsftpd restart
复制代码
注意:
网上文章很多有提及/etc/init.d/vsftpd start 之类的启动方式。但是这个目录下我不存在 vsftpd. 这个目录确实有: /etc/init/vsftpd.conf
  1. vsftpd 已經進化為 Upstart job
  2. 設定檔放在
  3. /etc/init/vsftpd.conf
复制代码
1.此用户只是用来使用ftp服务的
2.此用户不可登录服务器
3.此用户不能访问ftp指定文件夹之外的文件
(1) 创建一个用户ftp0
  1. useradd -d /home/ftp0 -m ftp0
复制代码
(2) 修改ftp0的暗码
  1. passwd ftp0
复制代码
  1. anonymous_enable=NO         # 不允许匿名访问
  2. write_enable=YES            # 允许写
  3. local_enable=YES            # 允许本地主机访问
  4. chroot_local_user=YES       # 只能访问自身的目录,此处有坑,需加上下面一行
复制代码
报错误信息:
  1. “500 OOPS: vsftpd: refusing to run with writable root inside chroot()”
复制代码
从2.3.5之后,vsftpd加强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!如果检查发现另有写权限,就会报该错误。
(1) 启用了chroot的话,根目录要设置为不可写
  1. chmod a-w /home/ftp0
复制代码
(2) 或者添加一句话
  1. allow_writeable_chroot=YES #允许写自身的目录
复制代码
但是添加这句话大概会导致服务重启失败。。。
无奈之下。。。chroot_local_user=YES这句话暂时不加。
  1. $   usermod -s /sbin/nologin ftp0
复制代码
after all these, restart the ftp service:
  1. # service vsftpd restart
  2. vsftpd stop/waiting
  3. vsftpd start/pre-start, process 10305
  4. # service vsftpd status
  5. vsftpd start/running, process 10305
复制代码
  1. # ftp
  2. ftp> open 192.168.2.108
  3. Connected to 192.168.2.108.
  4. 220 (vsFTPd 3.0.2)
  5. Name (192.168.2.108:hbb): ftp0
  6. 331 Please specify the password.
  7. Password:
  8. 530 Login incorrect.
  9. Login failed.
复制代码
需要 vi /etc/shells, 最后一行添加:
  1. /sbin/nologin
复制代码
重新测试:
  1. # ftp
  2. ftp> open 192.168.2.108
  3. Connected to 192.168.2.108.
  4. 220 (vsFTPd 3.0.2)
  5. Name (192.168.2.108:hbb): ftp0
  6. 331 Please specify the password.
  7. Password:
  8. 230 Login successful.
  9. Remote system type is UNIX.
  10. Using binary mode to transfer files.
复制代码
21 端口查看:
  1. netstat -npltu | grep 21
  2. tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      11398/vsftpd
复制代码
Ftp Java code

  1. package com.ryo.ftp;
  2. import org.apache.commons.net.ftp.FTPClient;
  3. import org.apache.commons.net.ftp.FTPReply;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. /**
  7. * @author houbinbin
  8. * @on 17/1/1
  9. */
  10. public class FTPTest {
  11.     private FTPClient ftp;
  12.     /**
  13.      * @param path     上传到ftp服务器哪个路径下
  14.      * @param addr     地址
  15.      * @param port     端口号
  16.      * @param username 用户名
  17.      * @param password 密码
  18.      * @return
  19.      * @throws Exception
  20.      */
  21.     private boolean connect(String path, String addr, int port, String username, String password) throws Exception {
  22.         boolean result = false;
  23.         ftp = new FTPClient();
  24.         int reply;
  25.         ftp.connect(addr, port);
  26.         ftp.login(username, password);
  27.         ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
  28.         reply = ftp.getReplyCode();
  29.         if (!FTPReply.isPositiveCompletion(reply)) {
  30.             ftp.disconnect();
  31.             return result;
  32.         }
  33.         ftp.changeWorkingDirectory(path);
  34.         result = true;
  35.         return result;
  36.     }
  37.     /**
  38.      * @param file 上传的文件或文件夹
  39.      * @throws Exception
  40.      */
  41.     private void upload(File file) throws Exception {
  42.         if (file.isDirectory()) {
  43.             ftp.makeDirectory(file.getName());
  44.             ftp.changeWorkingDirectory(file.getName());
  45.             String[] files = file.list();
  46.             for (int i = 0; i < files.length; i++) {
  47.                 File file1 = new File(file.getPath() + "\" + files[i]);
  48.                 if (file1.isDirectory()) {
  49.                     upload(file1);
  50.                     ftp.changeToParentDirectory();
  51.                 } else {
  52.                     File file2 = new File(file.getPath() + "\" + files[i]);
  53.                     FileInputStream input = new FileInputStream(file2);
  54.                     ftp.storeFile(file2.getName(), input);
  55.                     input.close();
  56.                 }
  57.             }
  58.         } else {
  59.             File file2 = new File(file.getPath());
  60.             FileInputStream input = new FileInputStream(file2);
  61.             ftp.storeFile(file2.getName(), input);
  62.             input.close();
  63.         }
  64.     }
  65.     //测试即使指定其他用户的文件夹,还要没有写的权限也无法上传。
  66.     public static void main(String[] args) throws Exception {
  67.         FTPTest t = new FTPTest();
  68.         t.connect("/home/ftp0/", "192.168.2.108", 21, "ftp0", "123456");
  69.         File file = new File("/Users/houbinbin/Downloads/ftptest.txt");
  70.         t.upload(file);
  71.     }
  72. }
复制代码
chat

详细介绍一下 FTP 协议

FTP(File Transfer Protocol)是用于在网络上进行文件传输的标准协议。
它是应用层协议,使用 TCP 端口 21 进行通信,重要用于在客户端和服务器之间上传、下载和管理文件。以下是对 FTP 协议的详细介绍:
FTP 协议概述

工作原理

FTP 协议采用客户端-服务器架构,重要涉及两个通信通道:
传输模式

FTP 有两种传输模式:
FTP 下令和响应

常见 FTP 下令

常见 FTP 响应代码

安全性

传统的 FTP 协议没有加密机制,传输的数据和凭据都是以明文形式发送的,这会导致安全风险。因此,衍生出了以下更安全的版本:
使用场景

FTP 的优缺点

优点

缺点

干系工具

结论

FTP 协议作为一种古老而广泛使用的文件传输协议,尽管在当代安全要求下显得不敷美满,但在一些场景中仍旧非常有用。
对于需要更高安全性的场景,可以选择 FTPS 或 SFTP 等替代方案。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4