前提:一定关关闭selinux!!!,然后重启服务器
安装
yum -y install vsftpd
systemctl enable vsftpd.service
systemctl start vsftpd.service
添加用户
adduser ftptest
passwd ftptest
配置文件
/etc/vsftpd/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
chown_username=ftpuser
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
chroot_local_user=NO
chroot_list_enable=NO
local_root=/data/ftp
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=NO
tcp_wrappers=YES
allow_writeable_chroot=YES
use_localtime=YES
pasv_enable=YES
pasv_min_port=30060
pasv_max_port=30090
java客户端上传文件
public static void main(String[] args) { FTPClient ftpClient = new FTPClient(); try (InputStream in = new FileInputStream(new File("d:/a.txt"))) { ftpClient.connect("192.168.88.131", 21); ftpClient.login("ftptest", "******"); boolean isChange = ftpClient.changeWorkingDirectory("test"); if (!isChange) { // 创建个人目录 ftpClient.makeDirectory("test"); // 切换 ftpClient.changeWorkingDirectory("test"); } // 文件类型 ftpClient.setFileType(FTPClient.LOCAL_FILE_TYPE); boolean is = ftpClient.storeFile(System.currentTimeMillis() + ".txt", in); System.out.println(is); } catch (IOException e) { e.printStackTrace(); } finally { try { ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
标签:ftp,enable,ftptest,vsftpd,linux,test,new,ftpClient From: https://www.cnblogs.com/wangdonghua/p/17891014.html