Skip to content

Commit 8f2baae

Browse files
committed
informative errors + sftp_path fix
1 parent 3c3a399 commit 8f2baae

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

bin/v-add-backup-host

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,17 @@ EOF
9696
# Verifications #
9797
#----------------------------------------------------------#
9898

99-
check_args '4' "$#" "TYPE HOST USERNAME PASSWORD [PATH] [PORT]"
100-
validate_format 'host' 'user'
101-
is_password_valid
102-
if [ "$type" = 'sftp' ]; then
103-
which expect >/dev/null 2>&1
104-
if [ $? -ne 0 ];then
105-
echo "Error: expect utility not found"
106-
log_event "$E_NOTEXIST" "$EVENT"
107-
exit $E_NOTEXIST
99+
if [ "$type" != 'local' ];then
100+
check_args '4' "$#" "TYPE HOST USERNAME PASSWORD [PATH] [PORT]"
101+
validate_format 'host' 'user'
102+
is_password_valid
103+
if [ "$type" = 'sftp' ]; then
104+
which expect >/dev/null 2>&1
105+
if [ $? -ne 0 ];then
106+
echo "Error: expect utility not found"
107+
log_event "$E_NOTEXIST" "$EVENT"
108+
exit $E_NOTEXIST
109+
fi
108110
fi
109111
fi
110112

@@ -122,7 +124,7 @@ if [ "$type" = 'ftp' ]; then
122124
ferror=$(echo $fconn |\
123125
grep -i -e failed -e error -e "can't" -e "not conn" -e "incorrect")
124126
if [ ! -z "$ferror" ]; then
125-
echo "Error: can't login to ftp server"
127+
echo "Error: can't login to ftp $user@$host"
126128
log_event "$E_CONNECT" "$EVENT"
127129
exit $E_CONNECT
128130
fi
@@ -143,12 +145,12 @@ if [ "$type" = 'sftp' ]; then
143145
if [ -z $port ]; then
144146
port=22
145147
fi
146-
sftmpdir="$sftp_path/vst.bK76A9SUkt"
148+
sftmpdir="$path/vst.bK76A9SUkt"
147149
sftpc "mkdir $sftmpdir" "rmdir $sftmpdir" > /dev/null 2>&1
148150
rc=$?
149151
if [[ "$rc" != 0 ]]; then
150152
case $rc in
151-
$E_CONNECT) echo "Error: can't login to sftp host";;
153+
$E_CONNECT) echo "Error: can't login to sftp $user@$host";;
152154
$E_FTP) echo "Error: can't create temp folder on the sftp host";;
153155
esac
154156
log_event "$rc" "$EVENT"

0 commit comments

Comments
 (0)