12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

bashでFTPファイル取得とエラー判定

Last updated at Posted at 2015-04-13

FTPをする機会も最近はないのですが、
shellからファイル取得して、エラー処理したかったので簡単に実装してみました。
エラーコードはRFC参照
http://hp.vector.co.jp/authors/VA002682/rfc959j.htm

# !/bin/bash
# 検出したいFTPのエラーをリストにしてエラー判定
FTP_ERROR_LIST=(421 425 426 450 451 452 500 501 502 503 504 530 532 550 551 552 553)

ftp -i -v -n << END > $FTP_LOG
open $FTP_SERVER
user $FTP_USER $FTP_PASSWD
bin
get $GET_FILE
quit
END

for err_no in ${FTP_ERROR_LIST[@]}
do
  grep "^$err_no " $FTP_LOG > /dev/null
  if [ "$?" -eq 0 ]; then
    echo "FTP Failed. [${err_no}]"
    exit 1
  fi
done
12
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?