lftp の使い方
SSHが使えない環境、FTPしかサポートしていないサービスにおいて、ファイルを安全にダウンロードしたい場合に何かいい方法ないかなーということで検索してみると、暗号化されたFTPであるFTPSというものがあるんだとか。
ということで今回は、FTPSをLinux等のコマンドライン上を使うことのできるlftpコマンドの備忘録。
事前準備
ftpではなくftps使ってくださいというような設定を事前に登録しておきます。
~/.lftprcに以下のように記述してください。
## aliasの設定 alias ls "ls -la" ## 通信の設定 set ftp:ssl-auth TLS set ftp:ssl-force true set ftp:ssl-allow yes set ftp:ssl-protect-list yes set ftp:ssl-protect-data yes set ftp:ssl-protect-fxp yes
使い方
実際にログイン。その後、debugモードを使用することで通信の様子を詳しく見ていきます。
$ lftp lftp :~> debug 10 # debugモードへ lftp :~> open -u USERNAME Server-Address #ログインします notice: cannot open /home/****/.netrc: No such file or directory # よくわかっていません。。。 Password: #パスードの入力 ---- Resolving host address... ---- 1 address found: ***.***.***.*** # では実際に接続して、lsコマンドを実行してみます lftp USERNAME@Server-Address:~> ls ---- dns cache hit ---- Connecting to Server-Address (***.***.***.***) port 21 <--- 220 ProFTPD 1.3.3a Server (Debian) [::ffff:***.***.***.***] ---> FEAT <--- 211-Features: <--- LANG en-US.UTF-8;en-US* <--- MDTM <--- MFMT <--- TVFS <--- AUTH TLS <--- UTF8 <--- MFF modify;UNIX.group;UNIX.mode; <--- MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*; <--- PBSZ <--- PROT <--- SITE MKDIR <--- SITE RMDIR <--- SITE UTIME <--- SITE SYMLINK <--- REST STREAM <--- SIZE <--- 211 End ---> AUTH TLS <--- 234 AUTH TLS successful # TLSプロトコルによる接続をしているっぽい? ---> LANG # 以下認証局の内容なので一部省略 Certificate: Issued by: Checking against: Trusted Certificate: Issued by: Checking against: Trusted Certificate: Issued by: Trusted <--- 200 Using default language en_US ---> OPTS UTF8 ON <--- 200 UTF8 set to on ---> OPTS MLST modify;perm;size;type;UNIX.group;UNIX.mode;UNIX.owner; <--- 200 OPTS MLST modify;perm;size;type;UNIX.group;UNIX.mode;UNIX.owner; ---> USER USERNAME <--- 331 Password required for USERNAME ---> PASS XXXX <--- 230 User USERNAME logged in ---> PWD <--- 257 "/" is the current directory ---> PBSZ 0 <--- 200 PBSZ 0 successful ---> PROT P <--- 200 Protection set to Private ---> PROT P <--- 200 Protection set to Private ---> PASV <--- 227 Entering Passive Mode (***,***,***,***,***,***). ---- Connecting data socket to (***.***.***.***) port ***** ---- Data connection established ---> LIST -la <--- 150 Opening ASCII mode data connection for file list Certificate: Issued by: Checking against: Trusted # 認証で問題なかったようです Certificate: Issued by: Checking against: Trusted Certificate: Issued by: Trusted ---- Got EOF on data connection ---- Closing data socket drwxr-xr-x 5 USERNAME USERNAME 4096 Oct 14 19:44 . drwxr-xr-x 5 USERNAME USERNAME 4096 Oct 14 19:44 .. <--- 226 Transfer complete copy: get hit eof copy: waiting for put confirmation copy: put confirmed store copy: get is finished - all done lftp USERNAME@Server-Address:/>
では、次に実際にgetしてみます(今回はdebugモードは使用していません)。
lftp USERNAME@Server-Address:/> get ubuntu-12.04.1-alternate-i386.iso `ubuntu-12.04.1-alternate-i386.iso' at 5111808 (0%) 772.1K/s eta:15m [Receiving data/TLS] #ダウンロード中 get ubuntu-12.04.1-alternate-i386.iso #ダウンロード後 725921792 bytes transferred in 1057 seconds (670.5K/s) lftp USERNAME@Server-Address:/>
ということで、これで問題なくFTPS接続できるかと思います。
FTPSを利用することでどのくらいファイル転送時の速度差が生まれてしまうかなんかいうデータは取っていないのでなんとも言えないですけど、体感的に約1/2程度の速度となるような気がします。ですが、やはりデータをFTPで普通にやり取りしてしまうのは危険すぎるよね…ということで今後はできるだけこっちを使う癖をつけていきたいところです。もちろんサポートされていなければ使えないんですけど。。。
また、lftpコマンドには"ミラーリング"なんて便利な機能もあるようなので必要に応じて今後は活用していきたいところですね。