@@ -29,6 +29,8 @@ arch=$(arch)
2929source /etc/hestiacp/hestia.conf
3030# shellcheck source=/usr/local/hestia/func/main.sh
3131source $HESTIA /func/main.sh
32+ # shellcheck source=/usr/local/hestia/func/backup.sh
33+ source $HESTIA /func/backup.sh
3234# load config file
3335source_conf " $HESTIA /conf/hestia.conf"
3436# Fetch current verison B2 CLI tool
@@ -38,123 +40,6 @@ source_conf "$HESTIA/install/upgrade/upgrade.conf"
3840b2cli=" /usr/local/bin/b2"
3941b2lnk=" https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/v$b2_v /b2-linux"
4042
41- # Defining ftp command function
42- ftpc () {
43- ftp -p -n $host $port << EOF
44- quote USER $user
45- quote PASS $password
46- binary
47- $1
48- $2
49- $3
50- quit
51- EOF
52- }
53-
54- # Defining sftp command function
55- sftpc () {
56- if [ " $privatekey " != " yes" ]; then
57- expect -f " -" " $@ " << EOF
58- set count 0
59- spawn /usr/bin/sftp -o StrictHostKeyChecking=no -o Port=$port $user @$host
60- expect {
61- -nocase "password:" {
62- send "$password \r"
63- exp_continue
64- }
65-
66- -re "Password for (.*)@(.*)" {
67- send "$password \r"
68- exp_continue
69- }
70-
71- -re "Couldn't|(.*)disconnect|(.*)stalled|(.*)not found" {
72- set count \$ argc
73- set output "Disconnected."
74- set rc $E_FTP
75- exp_continue
76- }
77-
78- -re ".*denied.*(publickey|password)." {
79- set output "Permission denied, wrong publickey or password."
80- set rc $E_CONNECT
81- }
82-
83- "sftp>" {
84- if {\$ count < \$ argc} {
85- set arg [lindex \$ argv \$ count]
86- send "\$ arg\r"
87- incr count
88- } else {
89- send "exit\r"
90- set output "Disconnected."
91- if {[info exists rc] != 1} {
92- set rc $OK
93- }
94- }
95- exp_continue
96- }
97-
98- timeout {
99- set output "Connection timeout."
100- set rc $E_CONNECT
101- }
102- }
103-
104- if {[info exists output] == 1} {
105- puts "\$ output"
106- }
107-
108- exit \$ rc
109- EOF
110- else
111- expect -f " -" " $@ " << EOF
112- set count 0
113- spawn /usr/bin/sftp -o StrictHostKeyChecking=no -o Port=$port -i $raw_password $user @$host
114- expect {
115-
116- -re "Couldn't|(.*)disconnect|(.*)stalled|(.*)not found" {
117- set count \$ argc
118- set output "Disconnected."
119- set rc $E_FTP
120- exp_continue
121- }
122-
123- -re ".*denied.*(publickey|password)." {
124- set output "Permission denied, wrong publickey or password."
125- set rc $E_CONNECT
126- }
127-
128- "sftp>" {
129- if {\$ count < \$ argc} {
130- set arg [lindex \$ argv \$ count]
131- send "\$ arg\r"
132- incr count
133- } else {
134- send "exit\r"
135- set output "Disconnected."
136- if {[info exists rc] != 1} {
137- set rc $OK
138- }
139- }
140- exp_continue
141- }
142-
143- timeout {
144- set output "Connection timeout."
145- set rc $E_CONNECT
146- }
147- }
148-
149- if {[info exists output] == 1} {
150- puts "\$ output"
151- }
152-
153- exit \$ rc
154- EOF
155- fi
156- }
157-
15843# ----------------------------------------------------------#
15944# Verifications #
16045# ----------------------------------------------------------#
@@ -201,6 +86,12 @@ if [ "$type" = 'ftp' ]; then
20186 if [ -z $port ]; then
20287 port=21
20388 fi
89+ PORT=$port
90+ USERNAME=$user
91+ PASSWORD=$password
92+ HOST=$host
93+ PRIVATEKEY=$privatekey
94+
20495 fconn=$( ftpc 2>&1 )
20596 ferror=$( echo $fconn \
20697 | grep -i -e failed -e error -e " can't" -e " not conn" -e " incorrect" )
@@ -231,6 +122,10 @@ if [ "$type" = 'sftp' ]; then
231122 if [ -z $port ]; then
232123 port=22
233124 fi
125+ PORT=$port
126+ USERNAME=$user
127+ PASSWORD=$password
128+ HOST=$host
234129 if [ -z $path ]; then
235130 sftmpdir=" vst.bK76A9SUkt"
236131 sftpc " mkdir $sftmpdir " " rmdir $sftmpdir " > /dev/null 2>&1
0 commit comments