-
Notifications
You must be signed in to change notification settings - Fork 1
/
sftp_runners.sh
81 lines (70 loc) · 1.64 KB
/
sftp_runners.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function get_port_from_args {
local next_is_port=0
for arg in "$@"; do
if [[ "$next_is_port" == 1 ]]; then
echo "$arg"
return
elif [[ "$arg" == "-p" ]]; then
local next_is_port=1
elif [[ "$arg" == -p* ]]; then
echo ${"$arg"#-p}
return
fi
done
}
function get_destination_from_args {
local next_is_port=0
for arg in "$@"; do
if [[ "$next_is_port" == 1 ]]; then
continue
elif [[ "$arg" == "-p" ]]; then
local next_is_port=1
elif [[ "$arg" == -p* ]]; then
continue
else
echo "$arg"
return
fi
done
}
function sftp_uri_from_ssh_cmd {
local port="$(get_port_from_args "$@")"
local dest="$(get_destination_from_args "$@")"
if [[ "$dest" == *@* ]]; then
local user="$(echo "$dest" | cut -d "@" -f 1)"
local host="$(echo "$dest" | cut -d "@" -f 2)"
else
local user=""
local host=""
fi
if [[ "$host" == *:* ]]; then
# Host is an IPv6 address (most likely)
local host="[$host]"
fi
echo -n "sftp://"
if [[ "$user" != "" ]]; then
echo -n "${user}@"
fi
echo -n "$host"
if [[ "$port" == "" ]]; then
echo
else
echo ":$port"
fi
}
function run_filezilla {
if is_wsl; then
local x86="$(wsl_win_var "ProgramFiles" | win_path_to_wsl)/FileZilla FTP Client/filezilla.exe"
local x86_64="$(wsl_win_var "ProgramW6432" | win_path_to_wsl)/FileZilla FTP Client/filezilla.exe"
if [ -f "$x86_64" ]; then
local fz_cmd="$x86_64"
else
local fz_cmd="$x86"
fi
else
local fz_cmd="filezilla"
fi
local uri="$(sftp_uri_from_ssh_cmd "$@")"
echo "\$" "$fz_cmd" "$uri"
exec "$fz_cmd" "$uri"
}