Linux Tutorial: Mount the FTP server to the local directory through CurlFTPfs

By default, rsync does not support file transfers directly using the FTP protocol. rsync is mainly used for efficient incremental file synchronization via rsync protocol or SSH protocol.

However, there is an alternative way to use rsync with CurlFTPfs for file synchronization via the FTP protocol. CurlFTPfs is a FUSE (Filesystem in Userspace) based file system that allows to mount an FTP server as a local file system.

The following is an example of file synchronization via FTP protocol using rsync and CurlFTPfs:

  1. Install CurlFTPfs: First, you need to install the CurlFTPfs tool. You can learn about its functions from its official website
    https://curlftpfs.sourceforge.io
    .
    Download link:
    https://sourceforge.net/projects/curlftpfs/files/latest/download

    insert image description here

  2. Mount FTP server: Use CurlFTPfs to mount an FTP server as a local directory. Execute the following command in the command prompt:

    curlftpfs -o user=$FTP_USER:$FTP_PASS $FTP_SERVER /mnt/ftp
    

    This will mount the FTP server to a local directory /mnt/ftp.

  3. File Synchronization with rsync: You can now use the rsync command to perform file synchronization with mounted FTP directories. The following are example commands:

    rsync -a --delete --exclude=".svn" --exclude=".git" --exclude=".DS_Store" --exclude="*.tmp" --exclude="*.bak" ./ /mnt/ftp/$remote_dir
    

    This command synchronizes the files in the current directory to the specified remote directory under the mounted FTP directory $remote_dir.

Note that this method uses CurlFTPfs to mount the FTP server as a local file system, and then uses the rsync command for file synchronization. It may not be as efficient and functional as using the rsync protocol or the SSH protocol directly, but may be a viable alternative in some cases.

Guess you like

Origin blog.csdn.net/a772304419/article/details/132413639