In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Vsftpd is the abbreviation of "very secure FTP daemon", and security is one of its biggest features.
Vsftpd is the name of a server running on a UNIX operating system. It can run on systems such as Linux, BSD, Solaris, HP-UNIX and so on. It is a completely free, open source ftp server software that supports many features that other FTP servers do not support.
For example: very high security requirements, bandwidth limitations, good scalability, can create virtual users, support IPv6, high speed, and so on.
Vsftpd is the most popular FTP server program in the Linux distribution. It is characterized by small and light, safe and easy to use.
1.1 installation
Command:
Yum install vsftpd-y
Configure Vsftpd
After installation, we have to configure it before it can be used properly.
Edit the configuration file for vsftpd
Vi / etc/vsftpd/vsftpd.conf
Find "anonymous_enable=YES" in the configuration file, change "YES" to "No", and disable anonymous login.
Add Boot Auto start
Chkconfig vsftpd on
Not sure if the boot item has been added, you can run chkconfig-list to view it.
1.2 create a user
Command: useradd ftpuser
Specify password: passwd ftpuser
This user is used to log in to the ftp server.
After such a user has been built, you can log in with this. Remember to log in normally instead of anonymously. The default path after login is / home/ftpuser.
-
Set the account of the FTP user, for example, the account is "ftpuser1", the directory is / home/ftpuser1, and the setting does not allow login through ssh.
Useradd-d / home/ftpuser-s / sbin/nologin ftpuser
Set the password for the account, for example, "ftpuser"
Passwd ftpuser
1.3 enable selinux permissions
VSFTPD is a FTP server program, and SELinux is a firewall component of CentOS. Because vsftpd is intercepted by SELinux by default, you will encounter the following problems with FTP:
1.226 Transfer done (but failed to open directory). (transfer completed, but failed to open path)
2.550 Failed to change directory (failed to change path)
3.
553 Could not create file.
4.
Or simply after sending the LIST command, the server does not respond and disconnects during the timeout.
When you encounter such a problem, it is usually that vsftpd does not have sufficient permissions and is likely to be blocked by SELinux.
View command: getsebool-a | grep ftp
Getsebool-a | grep ftpd# is the displayed permission, off is the off permission, on is the open permission allow_ftpd_anon_write-- > offallow_ftpd_full_access-- > offallow_ftpd_use_cifs-- > offallow_ftpd_use_nfs-- > offftpd_connect_db-- > offftpd_use_passive_mode-- > offftp_home_dir-- > off
Where ftp_home_dir and allow_ftpd_full_access must be on for vsftpd to have access to the ftp root directory, file transfer, and so on.
Setting command: setsebool-p xxxxxx on
[root@bogon] # setsebool-P allow_ftpd_full_access on [root@bogon ~] # setsebool-P ftp_home_dir on
1.4 set or turn off the firewall
Because the default port of ftp is 21, and centos is not open by default, modify the iptables file.
Setting: vi / etc/sysconfig/iptables
There is 22-j ACCEPT on the top of the line and another line of input is similar to that line, but change 22 to 21, and then: wq save.
To run it, restart iptables.
Restart: service iptables restart
Turn off the firewall: service iptables stop
Disable firewall restart: chkconfig iptables off
1.5 start vsftpd
Command: service vsftpd start
The java client (code) calls
Package com.jonychen.util;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.net.SocketException;import java.util.Date;import java.util.UUID;import org.apache.commons.net.ftp.FTP;import org.apache.commons.net.ftp.FTPClient;public class FtpUploadUtil {private static ThreadLocal threadLocal = new ThreadLocal (); private static ThreadLocal threadLocalHost = new ThreadLocal () Public static void init (String host,int port,String username,String password) throws SocketException, IOException {FTPClient client= threadLocal.get (); if (client==null) {client= new FTPClient (); / / 1. Connect client.connect (host,port); / / 2. Log in to client.login (username,password); threadLocal.set (client); threadLocalHost.set (host);}} public static String upload (InputStream local,String fileName,String path) throws SocketException, IOException {String datePath = DateUtil.date2Str (new Date (), "/ yyyy/MM/dd/"); / / path addition date path+=datePath; FTPClient client = threadLocal.get (); String host = threadLocalHost.get (); / / 3. Specify the file upload path (false does not exist) boolean exists = client.changeWorkingDirectory (path); if (! exists) {String pathArray [] = path.split ("/"); String temp = "/"; for (String p:pathArray) {temp+= (p + "/"); / / 4. If the file path does not exist, create (you can only create one level directory at a time) client.makeDirectory (temp);} / / re-specify the file upload path client.changeWorkingDirectory (path);} / / 5. Specify the file type client.setFileType (FTP.BINARY_FILE_TYPE); / / get the suffix String suffix = fileName.substring (fileName.lastIndexOf (".")); String uuid = UUID.randomUUID (). ToString (); / / 6. Perform upload client.storeFile (uuid+suffix, local); / / 7. Exit client.logout (); / / 8. Disconnect client.disconnect (); threadLocalHost.remove (); threadLocal.remove (); return "http://"+host+"/jonychen"+datePath+uuid+suffix;} public static void main (String [] args) throws SocketException, IOException {InputStream local = new FileInputStream (" D:\ Documents\\ Pictures\\ 01.png "); init (" 192.168.178.161 ", 21," ftpuser "," 111111 ") / / upload path String res = upload (local, "code.png", "/ home/ftpuser/ego"); System.out.println (res);}}
Summary
The above is the detailed steps of the installation and configuration of vsftpd under linux introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message for me. The editor will reply to you in time!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.