-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jan Vojta <[email protected]>
- Loading branch information
Jan Vojta
committed
Jul 1, 2020
1 parent
00a2d3a
commit 4d19e2d
Showing
1 changed file
with
14 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
#!/bin/bash | ||
|
||
#[email protected] | ||
# [email protected] | ||
# [email protected] | ||
|
||
host='' | ||
user='' | ||
password='' | ||
timeout=4 | ||
timeout=10 | ||
port=22 | ||
|
||
usage(){ | ||
|
@@ -15,7 +16,7 @@ usage: $0 <options> | |
-u user | ||
-p password | ||
-P port (defaults to 22) | ||
-t timeout (defaults to 4 seconds) | ||
-t timeout (defaults to 10 seconds) | ||
EOF | ||
exit 3 | ||
} | ||
|
@@ -39,13 +40,17 @@ fi | |
|
||
which lftp &>/dev/null || { echo 'You need to have lftp installed.'; exit 3; } | ||
|
||
timeout $timeout lftp -u ${user},${password} sftp://${host}:${port} <<EOF > /dev/null | ||
ls | ||
bye | ||
EOF | ||
# 'set net:max-retries 1' - 0 set unlimited, 1 - no retries | ||
# 'set net:timeout ${timeout}' - sets the network protocol timeout. | ||
# 'set net:reconnect-interval-base 5' - sets the base minimal time between reconnects | ||
|
||
OUT=$(lftp -u "${user},${password}" sftp://$host:$port -e "set net:timeout ${timeout};set net:max-retries 1;set net:reconnect-interval-base 5;ls;bye" 2>&1) | ||
|
||
if [[ $? -ne 0 ]]; then | ||
echo "Unable to connect to connect to ${host}"; exit 2; | ||
echo "Unable to connect to connect to ${host}" | ||
echo $OUT | ||
exit 2 | ||
else | ||
echo "Successfully connected to ${host}"; exit 0; | ||
echo "Successfully connected to ${host}" | ||
exit 0 | ||
fi |