Ubuntu article---Configuring FTP service
1. Install ftp service on ubuntu
1.1 Install vsftpd
sudo apt-get install vsftpd
1.2 Add user uftp
sudo useradd -m uftp
1.3 Set uftp user login password:
sudo passwd uftp
1.4 Edit the vsftpd.conf configuration file and add the following content at the end of the file:
sudo vim /etc/vsftpd.conf
write_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_enable=YES
userlist_deny=NO
local_root=/home/uftp
1.5 Add login user whitelist:
sudo vim /etc/vsftpd.user_list
uftp
Restart service
sudo service vsftpd restart
sudo service vsftpd status
Commonly used commands:
!dir 显示本地文件目录
lcd [dir] 将本地工作目录切换至dir
mput local-file: 将本地文件传输至远程主机
get remote-file[local-file] 将远程主机的文件remote-file传至本地磁盘的local-file
ls remote-dir 显示远程目录
mdelete remote-file 删除远程主机文件
reget remote-file 类似于get,但若local-file存在,则从上次传输中断处续传
bye 退出ftp会话;
2. Docker installation (the one I use)
2.1 Create directory
mkdir -p /docker/vsftp
2.2 Startup script
#!/bin/bash
docker run \
--name vsftpd \
-p 20:20 -p 21:21 -p 33361-33365:33361-33365 \
-v ./vsftp/ftpfile:/home/vsftpd \
-e FTP_USER=admin \
-e FTP_PASS=!Admin123 \
-e PASV_ADDRESS=127.0.0.1 \
-e PASV_MIN_PORT=33361 \
-e PASV_MAX_PORT=33365 \
--restart=always \
-d fauria/vsftpd
2.3 Access
ftp://127.0.0.1 账密 admin/!Admin123
2.4 How to create a new user
docker exec -it vsftpd /bin/bash
vi /etc/vsftpd/virtual_users.txt
# 这里的 admin 用户跟密码是安装的时候创建的
# 这里创建一个新用户
admin
!Admin123
uftp
123456
# 保存数据库
/usr/bin/db_load -T -t hash -f /etc/vsftpd/virtual_users.txt /etc/vsftpd/virtual_users.db
# 设置新用户家目录
mkdir -p /home/vsftpd/uftp
# 改变目录权限
chown ftp:ftp /home/vsftpd/uftp/
vsftpd changes account password in docker container
Enter the container, edit /etc/vsftpd/virtual_users.txt directly, add users and change the password.
2.5 Testing
ftp 127.0.0.1
2.6 Use
1. Connect to the server
Format: ftp [hostname| ip-address]
ftp 192.168.x.xx
2. Download file
get
format: get [remote-file] [local-file]
transfers the file from the remote host to the local host.
If you want to get /usr/your/1.htm on the remote server, then
ftp> get /usr/your/1.htm 1.htm (回车)
mget
format: mget [remote-files]
receives a batch of files from the remote host to the local host.
If you want to get all the files under /usr/your/ on the server, then
ftp> cd /usr/your/
ftp> mget . (回车)
3. Upload file
put
format: put local-file [remote-file]
transfers a local file to the remote host.
If you want to transfer the local 1.htm to the remote host /usr/your and rename it to 2.htm
ftp> put 1.htm /usr/your/2.htm (回车)
mput
format: mput local-files
transfers a batch of files from the local host to the remote host.
If you want to upload all html files in the current local directory to the server /usr/your/
ftp> cd /usr/your (回车)
ftp> mput *.htm (回车)
4. Disconnect
bye : interrupt the connection with the server.
ftp> bye (回车)
Additional usage:
在shell命令行下输入:
ftp 192.168.x.xx
根据提示输入正确的用户名和密码即可
常用操作命令(,号不是命令内容)
FTP>open [ftpservername],和指定的远程Linux FTP服务器连接
FTP>user [username] [password],使用指定远程Linux FTP服务器的用户登录
FTP>pwd,显示远程Linux FTP服务器上的当前路径文章地址https://www.yii666.com/blog/144054.html
FTP>ls,列出远程Linux FTP服务器上当前路径下的目录和文件
FTP>dir,列出远程Linux FTP服务器上当前路径下的目录和文件(同上)
FTP>mkdir [foldname],在远程Linux FTP服务器上当前路径下建立指定目录
FTP>rmdir [foldname],删除远程Linux FTP服务器上当前路径下的指定目录
FTP>cd [foldname],更改远程Linux FTP服务器上的工作目录
FTP>delete [filename],删除远程Linux FTP服务器上指定的文件
FTP>rename [filename] [newfilename],重命名远程Linux FTP服务器上指定的文件
FTP>close,从远程Linux FTP服务器断开但保留FTP命令参数提示网址:yii666.com<文章来源地址:https://www.yii666.com/blog/144054.html
FTP>disconnect,从远程Linux FTP服务器断开但保留FTP命令参数提示(同上)
FTP>bye,结束和远程Linux FTP服务器的连接
FTP>quit,结束和远程Linux FTP服务器的连接(同上)
FTP>!,直接从远程Linux FTP服务器进入到本地shell中
FTP>exit,(接上步)从本地shell环境中返回到远程Linux FTP服务器环境下
FTP>!ls,列出本地机器上当前路径下的目录和文件
FTP>lcd [foldname],更改本地机器的工作目录
FTP>?,显示ftp命令说明网址:yii666.com
FTP>help,显示ftp命令说明(同上)
PS:最好将要进行传输的文件或文件夹的权限设置成775 或777
3. Download data
# 1.连接
ftp xx.xx.xx.xx
# 2. 输入"prompt"命令(打开交互模式),输入执行第二次则关闭。如交互打开,下载文件会 提示是否下载,若批量下载很麻烦,所以关闭交互。
prompt
# 3. 批量下载
mget *
reference:
- https://blog.csdn.net/qq_45031509/article/details/128016689
- https://blog.csdn.net/mshxuyi/article/details/119935069
- https://www.cnblogs.com/biaogejiushibiao/p/9268533.html