FTPクライアントのcurlftpfsをインストールする手順を記載します。
Table of Contents
1 curlftpfsのインストール
curlftpfsパッケージをインストールします。
> sudo zypper -n in curlftpfs
2 curlftpfsでマウント
curlftpfsコマンドでmntディレクトリへマウントします。
> FTP_SERVER=$(hostname)-ftp-server.hiroom2.com
> FTP_USERNAME=guest
> FTP_PASSWORD=guest
> mkdir mnt
> curlftpfs -o user=${FTP_USERNAME} "${FTP_SERVER}" mnt
Enter host password for user '${FTP_USERNME}':
user=<username>:<password>でパスワードを指定することもできます。
> curlftpfs -o user=${FTP_USERNAME}:${FTP_PASSWORD} "${FTP_SERVER}" mnt
user=<username>:で~/.netrcに記載されたパスワードが使用されます。
> cat <<EOF > ~/.netrc
machine ${FTP_SERVER}
login ${FTP_USERNAME}
password ${FTP_PASSWORD}
EOF
> chmod 600 ~/.netrc
> curlftpfs -o user=${FTP_USERNAME}: "${FTP_SERVER}" mnt
ユーザを指定しない場合は匿名ユーザとしてマウントします。
> curlftpfs "${FTP_SERVER}" mnt
allow_otherを指定すると他ユーザからのアクセスを許可します。 allow_rootを指定するとrootユーザからのアクセスを許可します。 allow_otherとallow_rootを指定しない場合はマウントしたユーザのみがアクセスできます。
> curlftpfs -o user=${FTP_USERNAME},allow_other "${FTP_SERVER}" mnt
3 起動時にマウント
他のファイルシステムと同様に/etc/fstabに追記します。ネットワーク初期化前にマウントするのを防ぐために、_netdevをオプションを指定する必要があります。 x-systemd.automountにマウントさせるために、x-systemd.automountをオプションに指定する必要があります。
> OPT=_netdev,x-systemd.automount,allow_other
> cat <<EOF | sudo tee -a /etc/fstab
curlftpfs#${FTP_USERNAME}:${FTP_PASSWORD}@${FTP_SERVER} \
/mnt fuse ${OPT} 0 0
EOF
パスワードを記載しないようにするには/root/.netrcを作成します。
> cat <<EOF | sudo tee /root/.netrc
machine ${FTP_SERVER}
login ${FTP_USERNAME}
password ${FTP_PASSWORD}
EOF
> sudo chmod 600 /root/.netrc
> OPT=_netdev,x-systemd.automount,allow_other
> cat <<EOF | sudo tee -a /etc/fstab
curlftpfs#${FTP_USERNAME}:@${FTP_SERVER} /mnt fuse ${OPT} 0 0
EOF