Skip to content

Commit affc2ba

Browse files
committed
Add an exclude filter for files through DL_EXCLUDE_REGEX (Issue #27)
1 parent 12d90eb commit affc2ba

File tree

6 files changed

+77
-22
lines changed

6 files changed

+77
-22
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ script:
2323
- ./test02_wget_sha1_text.sh
2424
- ./test03_curl_md5_sqlite3.sh
2525
- ./test04_curl_sha1_sqlite3_secure.sh
26+
- ./test05_exclude.sh
2627

2728
after_script:
2829
- tree -pu /opt/ftpgrab/ /var/log/ftpgrab/ $HOME/download/
2930

3031
notifications:
31-
slack:
32-
secure: WuzYm7aWEyuYdLGA9PMv7RdYQxOhaJMsWbVv3aneTX+y4Pk2MdgWNoUqu87NZsbjvpmH7UpH8JxJeo4QZ2bEVgrFvuozxY8Z3D6C0ZstvWfZyHQWVVwcy0zuLxJ1lFU3nZHftLl6S5zQQ4drJd/JVaI3f7qBVUMOEUDkYh4C678=
32+
webhooks:
33+
secure: QjLOJOPsNZxoVcSI+fn6tWXp7TDb+t2Eykm55TI85ctb0JA8yepQDLfPT0HfnYt/Hnd8bME3No9JPE8H1kDlR+XaaG1fFWIBnQdDWySJKDIndOGb8gKLDUbvFPO/YRoLIsTrItEh//EJgSApkwqVlZbJIJ+if1lPzIsIy9/dG+3gaTc99VR7O0RZuwkkC0t+xgbMjrFpTSmgbMPAOB4jwFqrNKUQBc5Kxjd/wIqM1ZsWtQ4lFHUKQJBgTsnH5o2JMkpkwUJ+XHrWnmknJTD4mVwl1es2axUicumhERiyGN1WrDwY2kVs9UI0AqLHYNeBP3aNXV2lwngkmt59MIFpnqT6ELlOb34WKDCaNTXMzHBphtzevzXshGOUPB6be0S4ai2xukAq1rOzDhUSNzhrupxjjb8FhxHz0TtoKjcAO1ZlT+92dIgcEPx3qf3Y9e46lUKEokidmZOhwHnT0D0uF7LJ+c2z9oopG7DyzBNIVDTyitQmdlvfCUc+RJRfnDQ/8v5qoI8TzkJ6VXwpyWWdZJRJIknkWwf2BKxkGP1pCCSsfSiSKAvsRa1GPq6ztfnfC4jcrfurnSFrLmeGc4+kvDXuYiC4NZ6LoezDsjUKnR3gf1s0IvZNurcb6PA0yPIoAnOWzUYR8ObOcU1gs51zvXsDqxZC3D+O4lChHWsOy8U=

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 4.3.0 (2017/12/26)
4+
5+
* Add an exclude filter for files through [DL_EXCLUDE_REGEX](https://ftpgrab.github.io/doc/configuration/#dl_exclude_regex) (Issue #27)
6+
37
## 4.2.4 (2017/11/01)
48

59
* Do not exit if connection failed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2013-2017 Cr@zy
3+
Copyright (c) 2013-2017 CrazyMax
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

ftpgrab.conf

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ DL_USER=""
2323
DL_GROUP=""
2424
DL_CHMOD=""
2525
DL_REGEX=""
26+
DL_EXCLUDE_REGEX=""
2627
DL_RETRY=3
2728
DL_RESUME=0
2829
DL_SHUFFLE=0

ftpgrab.sh

+39-19
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
###################################################################################
44
# #
5-
# FTPGrab v4.2.4 #
5+
# FTPGrab v4.3.0 #
66
# #
77
# Simple script to grab your files from a remote FTP server. #
88
# #
99
# MIT License #
10-
# Copyright (c) 2013-2017 Cr@zy #
10+
# Copyright (c) 2013-2017 CrazyMax #
1111
# #
1212
# Permission is hereby granted, free of charge, to any person obtaining a copy #
1313
# of this software and associated documentation files (the "Software"), to deal #
@@ -282,6 +282,7 @@ function ftpgrabProcess() {
282282
local _SKIP_DL=0
283283
local _RESUME=0
284284
local _START_TIME=$(awk "BEGIN{srand();print srand()}")
285+
local _EXCLUDE=0
285286
if [ ${_DEST_FILE: -1} == "/" ]
286287
then
287288
mkdir -p "$_DEST_FILE"
@@ -292,24 +293,42 @@ function ftpgrabProcess() {
292293
ftpgrabAddLog "Hash: $_SRC_HASH"
293294
ftpgrabAddLog "Size: $(ftpgrabGetHumanSize "$_SRC_FILE_PROC")"
294295

295-
# Check validity
296-
local _DL_STATUS=$(ftpgrabIsDownloaded "$_SRC_FILE_PROC" "$_SRC_FILE")
297-
298-
if [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_NEVER_DL} ]
299-
then
300-
ftpgrabAddLog "Status: Never downloaded..."
301-
elif [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_SIZE_EQUAL} ]
302-
then
303-
local _SKIP_DL=1
304-
ftpgrabAddLog "Status: Already downloaded and valid. Skip download..."
305-
elif [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_SIZE_DIFF} ]
296+
# Check exclude
297+
if [ ! -z "$DL_EXCLUDE_REGEX" ]
306298
then
307-
if [ "$DL_RESUME" == "1" ]; then local _RESUME=1; fi
308-
ftpgrabAddLog "Status: Exists but sizes are different..."
309-
elif [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_HASH_EXISTS} ]
299+
IFS=';' read -ra EXCLUDE_REGEX <<< "$DL_EXCLUDE_REGEX"
300+
for _P in "${EXCLUDE_REGEX[@]}"; do
301+
if $(echo "$_SRC_FILE_SHORT" | grep -Eq "^$_P$")
302+
then
303+
local _EXCLUDE=1
304+
local _SKIP_DL=1
305+
ftpgrabAddLog "Status: File skipped with exclude filter '$_P'..."
306+
break
307+
fi
308+
done
309+
fi
310+
311+
# Check validity
312+
if [ "$_EXCLUDE" == "0" ]
310313
then
311-
local _SKIP_DL=1
312-
ftpgrabAddLog "Status: Hash sum exists. Skip download..."
314+
local _DL_STATUS=$(ftpgrabIsDownloaded "$_SRC_FILE_PROC" "$_SRC_FILE")
315+
316+
if [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_NEVER_DL} ]
317+
then
318+
ftpgrabAddLog "Status: Never downloaded..."
319+
elif [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_SIZE_EQUAL} ]
320+
then
321+
local _SKIP_DL=1
322+
ftpgrabAddLog "Status: Already downloaded and valid. Skip download..."
323+
elif [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_SIZE_DIFF} ]
324+
then
325+
if [ "$DL_RESUME" == "1" ]; then local _RESUME=1; fi
326+
ftpgrabAddLog "Status: Exists but sizes are different..."
327+
elif [ ${_DL_STATUS:0:1} -eq ${FILE_STATUS_HASH_EXISTS} ]
328+
then
329+
local _SKIP_DL=1
330+
ftpgrabAddLog "Status: Hash sum exists. Skip download..."
331+
fi
313332
fi
314333

315334
# Check if download skipped and want to hide it in log file
@@ -501,6 +520,7 @@ DL_USER=""
501520
DL_GROUP=""
502521
DL_CHMOD=""
503522
DL_REGEX=""
523+
DL_EXCLUDE_REGEX=""
504524
DL_RETRY=3
505525
DL_RESUME=0
506526
DL_SHUFFLE=0
@@ -553,7 +573,7 @@ mkdir -p "$HASH_DIR"
553573
if [ ! -d "$HASH_DIR" ]; then ftpgrabEcho "ERROR: Cannot create dir $HASH_DIR with $(whoami) user"; exit 1; fi
554574
if [ ! -w "$HASH_DIR" ]; then ftpgrabEcho "ERROR: Dir $HASH_DIR is not writable by $(whoami)"; exit 1; fi
555575

556-
ftpgrabEcho "FTPGrab v4.2.4 ($BASENAME_FILE - $(date +"%Y/%m/%d %H:%M:%S"))"
576+
ftpgrabEcho "FTPGrab v4.3.0 ($BASENAME_FILE - $(date +"%Y/%m/%d %H:%M:%S"))"
557577
ftpgrabEcho "--------------"
558578

559579
# Check required packages

tests/test05_exclude.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
source common.sh
4+
TEST_NAME=$(echo $(basename $0) | sed -e 's/^[SK][0-9]*//' -e 's/\.sh$//')
5+
6+
CONFIG_FILE="/opt/ftpgrab/conf/$TEST_NAME.conf"
7+
DIR_DEST="$HOME/download/$TEST_NAME"
8+
9+
# Clean
10+
rm -f "$CONFIG_FILE"
11+
rm -rf "$DIR_DEST"
12+
rm -f "/opt/ftpgrab/hash/$TEST_NAME*"
13+
14+
# Edit config
15+
cp -f "$DEFAULT_CONFIG_FILE" "$CONFIG_FILE"
16+
sed "s#DIR_DEST=\"$DEFAULT_DIR_DEST\"#DIR_DEST=\"$DIR_DEST\"#" -i "$CONFIG_FILE"
17+
#sed "s#DEBUG=0#DEBUG=1#" -i "$CONFIG_FILE"
18+
sed "s#FTP_HOST=\"$DEFAULT_FTP_HOST\"#FTP_HOST=\"$SERVER1_IP\"#" -i "$CONFIG_FILE"
19+
sed "s#FTP_USER=\"\"#FTP_USER=\"$SERVER1_USER\"#" -i "$CONFIG_FILE"
20+
sed "s#FTP_PASSWORD=\"\"#FTP_PASSWORD=\"$SERVER1_PASSWORD\"#" -i "$CONFIG_FILE"
21+
sed "s#DL_EXCLUDE_REGEX=\"\"#DL_EXCLUDE_REGEX=\"*.txt\"#" -i "$CONFIG_FILE"
22+
23+
# Launch
24+
ftpgrab "$TEST_NAME.conf"
25+
26+
# Check
27+
if [ ! -z $(find "$DIR_DEST" -name "*.txt" -print0) ]; then
28+
exit 1
29+
fi

0 commit comments

Comments
 (0)