Linux下用curlftpfs挂载FTP服务器
1、安装curlftpfs
1.1 安装DAGrepository
由于CentOS系统不能直接使用yum install curlftpfs 安装curltftpfs,所以需要先安装DAG repository
rpm -Uhv http://apt.sw.be/RedHat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
或者,先在网上搜索rpmforge-release,到:http://www.rpmfind.net/linux/rpm2html/search.php?query=rpmforge-release,下载rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm,下载后,上传到AS6 64服务器,执行rpm -Uhv rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm 进行安装
1.2 安装curlftpfs :yum install curlftpfs
2、挂载ftp服务器
【已知:这里ftp服务器为192.168.201.1,其中ftp用户为ftp_test,密码123,可访问的目录为/home/ftp_test,另存在系统b,b系统中存在目录/home/b/doc2】
2.1实现效果:ftp服务器上的/home/ftp_test映射到系统b的/home/b/doc2 目录
2.2错误:
在系统b执行如下命令,提示“server denided you to change to the given directory”
curlftpfs -o rw,uid=500,gid=500,allow_other,codepage=utf8 ftp://ftp_test:123@192.168.201.1/home/ftp_test /home/b/doc2
[root@Centos6x64 logs]# curlftpfs -o rw,uid=500,gid=500,allow_other,codepage=utf8 ftp://ftp_test:123@192.168.201.1/home/ftp_test /home/b/doc2
Error connecting to ftp: Server denied you to change to the given directory
错误原因:
用户ftp_test在ftp服务器上的路径不对:在ftp服务器中执行cat /etc/passwd,可以看到用户ftp_test的默认路径为/home/ftp_test,所以上一条命令,用户ftp_test的路径变成了/home/ftp_test/home/ftp_test
[root@Centos6x64 vsftpd]# cat /etc/passwd
............................................
..........................................
#可以看到很多用户,这里主要看用户ftp_test
ftp_test:x:500:500::/home/ftp_test:/sbin/nologin
更正 :
在系统b重新输入如下命令,挂载成功
curlftpfs -o rw,uid=500,gid=500,allow_other,codepage=utf8 ftp://ftp_test:123@192.168.201.1/ /home/b/doc2
效果:
在b系统的/home/b/doc2目录下可以看到ftp服务器/home/ftp_test目录下的文件
2.3命令参数详解:
curlftpfs -o codepage=utf8 ftp://username:password@192.168.192.168 /ftp
codepage: 编码
username: FTP用户名
password: FTP密码
192.168.1.111: FTP地址
/ftp: 准备挂载到的路径
开放权限
这样其它用户也能读写了,uid和gid改成你自己的id
sudo curlftpfs –o rw,allow_other,uid=0,gid=0 ftp:// username: password @192.168.1.111 /ftp
其中:查看uid和gid可通过以下命令:
可以通过查看/etc/passwd文件来确定自己的uid和gid
cat /etc/passwd | grep 你的用户名
[root@Centos6x64 vsftpd]# cat /etc/passwd |grep ftp_test
ftp_test:x:500:500::/home/ftp_test:/sbin/nologin
其中x后面的两个数就是uid和gid了,这里uid是500,gid也是500
2.4开机自动挂载
在x系统b的/etc/fstab文件的最后面添加:
curlftpfs#ftp_test:123@192.168.201.1/ /home/b/doc3 fuse rw,uid=500,gid=500,user,sync_read,allow_other 0 0
- rw:读写权限,可以只留读权限(ro)
2.5移除挂载
在系统b:执行如下命令
方法1:ps -ef|grep ftp,然后使用kill来停掉挂载进程
方法2:fusermount -u /home/b/doc2
方法3:umount /home/b/doc2
参考:https://www.linuxidc.com/Linux/2011-05/35917.htmLinux下用curlftpfs挂载FTP服务器 [CentOS]