ftp服务挂载本地目录:Linux工具CurlFTPfs安装与使用

CurlFTPfs 是一个基于 FUSE(Filesystem in Userspace)的文件系统,它允许将 FTP 服务器挂载为本地文件系统。下载地址:https://sourceforge.net/projects/curlftpfs/files/latest/download

软件安装过程如下,底层是centos7+Intel x86环境

--下载后解压
[root@localhost software]# tar -xzvf curlftpfs-0.9.2.tar.gz
curlftpfs-0.9.2  curlftpfs-0.9.2.tar.gz
[root@localhost software]# cd curlftpfs-0.9.2/
--编译(提前安装以下组件,不然可能缺失报错)
[root@localhost curlftpfs-0.9.2]# yum install fuse* 
[root@localhost curlftpfs-0.9.2]# yum install libcurl
[root@localhost curlftpfs-0.9.2]# yum install libcurl-devel
[root@localhost curlftpfs-0.9.2]# yum install glib*
[root@localhost curlftpfs-0.9.2]# 
[root@localhost curlftpfs-0.9.2]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
…………
configure: creating ./config.status
config.status: creating Makefile
config.status: creating compat/Makefile
config.status: creating tests/Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@localhost curlftpfs-0.9.2]# make -j 8
make  all-recursive
make[1]: Entering directory '/soft/software/curlftpfs-0.9.2'
Making all in compat
…………
gcc -g -O2 -Wall -W -Wno-sign-compare -D_REENTRANT -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/fuse -D_FILE_OFFSET_BITS=64 -o curlftpfs ftpfs.o -pthread  libcurlftpfs.a -lglib-2.0 -lfuse -lcurl  
make[2]: Leaving directory '/soft/software/curlftpfs-0.9.2'
make[1]: Leaving directory '/soft/software/curlftpfs-0.9.2'
[root@localhost curlftpfs-0.9.2]# make install
Making install in compat
make[1]: Entering directory '/soft/software/curlftpfs-0.9.2/compat'
…………
test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
  /bin/sh ./libtool --mode=install /usr/bin/install -c 'curlftpfs' '/usr/local/bin/curlftpfs'
/usr/bin/install -c curlftpfs /usr/local/bin/curlftpfs
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/soft/software/curlftpfs-0.9.2'
make[1]: Leaving directory '/soft/software/curlftpfs-0.9.2'
[root@localhost curlftpfs-0.9.2]#  

首先确保ftp服务是正常的

[root@localhost ~]# yum install ftp
[root@localhost ~]# ftp
ftp> open 192.168.1.200
Connected to 192.168.1.200 (192.168.1.200).
220 Microsoft FTP Service
Name (192.168.1.200:root): lzb
331 Password required
Password:
230 User logged in.
Remote system type is Windows_NT.
ftp> ls
227 Entering Passive Mode (192,168,1,200,247,33).
125 Data connection already open; Transfer starting.
07-17-23  05:12PM               431104 DM8.doc
226 Transfer complete.
ftp> exit
221 Goodbye.
[root@localhost ~]# 

创建本地目录用来挂载ftp

[root@localhost soft]# mkdir -p /soft/curlftpfs_local     

使用 CurlFTPfs 将 FTP 服务器挂载为本地目录

---标准命令:curlftpfs -o user=$FTP_USER:$FTP_PASS $FTP_SERVER /mnt/ftp
[root@localhost soft]# curlftpfs -o user=lzb:123456789 ftp://192.168.1.200 /soft/curlftpfs_local/
[root@localhost soft]# df -h 
Filesystem                      Size  Used Avail Use% Mounted on
devtmpfs                        1.9G     0  1.9G   0% /dev
tmpfs                           1.9G  1.1M  1.9G   1% /dev/shm
tmpfs                           1.9G   11M  1.9G   1% /run
tmpfs                           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/nvme0n1p3                   28G  6.2G   22G  23% /
/dev/mapper/vg_soft-lv_soft      50G   29G   22G  58% /soft
/dev/nvme0n1p1                  295M  144M  152M  49% /boot
tmpfs                           376M     0  376M   0% /run/user/2016
tmpfs                           376M   16K  376M   1% /run/user/42
tmpfs                           376M  4.0K  376M   1% /run/user/1002
tmpfs                           376M  4.6M  372M   2% /run/user/0
/dev/sr0                        6.7G  6.7G     0 100% /run/media/root/RHEL-8-0-0-BaseOS-x86_64
curlftpfs#ftp://192.168.1.200/  954G     0  954G   0% /soft/curlftpfs_local
[root@localhost soft]# 

配置为开机自启

[root@localhost soft]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Sep  6 07:02:04 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=eacd335a-16fc-4276-b54d-a1c07b29fe1e /                       xfs     defaults        0 0
UUID=c991f507-071d-4f03-b651-dbeaa9b3b516 /boot                   xfs     defaults        0 0
UUID=3eb67850-0adf-4a5d-82f6-f3c953d21f4d swap                    swap    defaults        0 0
/dev/vg_soft/lv_soft /soft xfs defaults 0 0
curlftpfs#ftp://lzb:wimf1991@192.168.1.200/ /soft/curlftpfs_local fuse rw,uid=1001,gid=2001,umask=0022,user,suid,sync_read,allow_other,exec,auto,utf8,_netdev,direct_io 0 0


[root@localhost soft]# 

测试目前虽然可以挂载,但是直接通过ftp挂载目录创建文件并编辑,第一遍可以编辑,但是保存会提示Fsync failed,但是实际是存进去的,第二次之后就无法修改生效;挂载目录中文件cp也会报错Input/output error,但是cp到其他非ftp挂载目录是没有问题的。目前貌似不是操作问题是curlftpfs版本及依赖的fuse\libcurl组件版本直接的关系,某些版本组合下没有这些问题,有用到的伙伴欢迎分享。

原创文章,作者:lzb,如若转载,请注明出处:https://www.wlkjzx.com/2023/10/18/ftp%e6%9c%8d%e5%8a%a1%e6%8c%82%e8%bd%bd%e6%9c%ac%e5%9c%b0%e7%9b%ae%e5%bd%95%ef%bc%9alinux%e5%b7%a5%e5%85%b7curlftpfs%e5%ae%89%e8%a3%85%e4%b8%8e%e4%bd%bf%e7%94%a8/

(0)
打赏 微信扫一扫 微信扫一扫
lzblzb
上一篇 2024年8月10日
下一篇 2024年4月24日

相关推荐

发表回复

登录后才能评论