TypeCodes

Redhat/CentOS通过yum安装与配置vsFTPd的详细步骤

上一篇文章《Redhat/CentOS通过yum安装与配置vsFTPd的详细步骤》介绍了如何在vmware8中的redhat5.3中安装vsftpd软件,那么这篇文章就继续说说如何在windows系统中,通过vsftpd服务实现虚拟机vmware中的文件上传和下载等简单功能。

测试环境是在windows中用cmd连接虚拟机中的linux主机服务器,当然更简单的方式是直接在windows中用常见的ftp客户端软件进行文件的上传与下载。只是BZ觉得既然学习了linux,就要把shell命令学好,所以总结了下面这篇教程。

1 在windows中通过CMD命令测试能否连接上远端ftp主机服务

cmd命令ping主机

2 在windows中通过CMD命令登录远端服务器
C:\Users\vfhky>ftp 192.168.198.128
连接到 192.168.198.128。
220 (vsFTPd 2.0.5)
用户(192.168.198.128:(none)): oracle  (测试的RHEL本地账户为oracle)
331 Please specify the password.
密码:
230 Login successful.
ftp> pwd
257 "/home/oracle"
3 实现文件的下载
ftp> ls  (列出/home/oracle文件夹下面的目录)
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
Desktop
LOG_cat_owb.TXT
app
database
install2013-03-13_07-26-25.log
linux_11gR2_database_1of2.zip
linux_11gR2_database_2of2.zip
oraInventory
oradiag_oracle
show
226 Directory send OK.
ftp> get LOG_cat_owb.TXT(下载文件)
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for LOG_cat_owb.TXT (354 bytes).
226 File send OK.
ftp: 收到 354 字节,用时 0.01秒 44.25千字节/秒。

这个时候我们已经把LOG_cat_owb.TXT下载到了C:\Users\vfhky(这个是当前cmd终端的所在位置)中了。

4 单个文件的上传(put)
ftp> put c:/users/vfhky/desktop/1.jpg
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 42814 字节,用时 0.02 2038.76千字节/秒。
5 多个文件的上传(mput)
ftp> mput c:/users/vfhky/desktop/*.rpm (把所有以.rpm结尾的软件包上传)
mput c:/users/vfhky/desktop/gcc-4.1.2-44.el5.i386.rpm?
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 5478116 字节,用时 0.06秒 99602.11千字节/秒。
mput c:/users/vfhky/desktop/gcc-c++-4.1.2-44.el5.i386.rpm?
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 3593724 字节,用时 0.04秒 89843.10千字节/秒。

或者

ftp> mput c:/users/vfhky/desktop/gcc-4.1.2-44.el5.i386.rpm c:/users/vfhky/deskto
p/gcc-c++-4.1.2-44.el5.i386.rpm
mput c:/users/vfhky/desktop/gcc-4.1.2-44.el5.i386.rpm?
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 5478116 字节,用时 0.06 85595.56千字节/秒。
mput c:/users/vfhky/desktop/gcc-c++-4.1.2-44.el5.i386.rpm?
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 File receive OK.
ftp: 发送 3593724 字节,用时 0.05 73341.31千字节/秒。
6 在vsftpd上传/下载过程中可能出现的错误
6.1 在windows中能够ping通主机,但是无法连接远端ftp。

这个可能是linux中防火墙的缘故,可以通过[root@localhost ~]# service iptables stop关闭redhat中的防火墙。

6.2 出现类似以下的错误提示
ftp> put c:/users/vfhky/desktop/1.jpg /
200 PORT command successful. Consider using PASV.
553 Could not create file.

原因:SELinux对vsftpd服务的限制,SELinux ftp daemon policy is customizable based on least access required. So by default SElinux does not allow users to login and read their home directories. If you are setting up this machine as a ftpd server and wish to allow users to access their home directorories, you need to set the ftp_home_dir boolean(SELinux的ftp守护进程的策略是基于最少访问需求权限定制的。因此,通过默认的SELinux不允许用户登录并读取它们的主目录。如果你设置这台机器作为一个ftpd服务器,并希望允许用户访问他们的home目录,你需要设置ftp_home_dir为布尔值。)所以要关闭SELinux对vsftpd的保护,以root用户在终端输入指令:

[root@localhost ~]# setsebool -P ftpd_disable_trans 1
或者[root@localhost ~]# setsebool -P ftp_home_dir=1
或者[root@localhost ~]# setsebool -P ftpd_disable_trans on
或者[root@localhost ~]# setsebool -P ftp_home_dir on
[root@localhost ~]# service vsftpd restart
6.3 出现类似的错误提示
500 OOPS: cannot change directory:/root
500 OOPS: child died
Connection closed

这类的500 OOPS错误的解决方法同2,或者最终极的方法是关闭selinux:

[root@localhost ~]# vi /etc/selinux/config
SELINUX=disabled
打赏支持

Comments »