-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload-ftp.zsh
More file actions
69 lines (58 loc) · 1.53 KB
/
upload-ftp.zsh
File metadata and controls
69 lines (58 loc) · 1.53 KB
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
#!/bin/zsh
# upload script (a rewrite using zsh's built-in ftp functions)
# usage: upload [-[h/p <path>]] <filenames> (path defaults to 'upload')
# note: will overwrite any file that exists on remote(!)
program_name=$(basename $0)
# get passwords and proper variables from secrets file
source $HOME/local/share/.secrets
show_invalid_usage() {
echo "$program_name: too few arguments (or first parameter non-existant)
Try '$program_name --help' for more information."
}
show_help() {
echo "Usage: $program_name [OPTION]... FILE...
Upload a file to a remote ftp server
-p, --path remote path to send file
-h, --help display this help and exit"
}
# handle command line arguments
while [[ $1 == -* ]]; do
case "$1" in
-h|--help) show_help; exit 0;;
-c|--clipboard); clipboard=1; shift;;
-p|--path)
if [ "$2" ]; then
ftp_upload_path=$2
shift 2
else
show_help
exit
fi
;;
esac
done
# check there is at least one argument (and it exists)
if [ ! "$@[1]" ] || [ ! -e "$@[1]" ]; then
show_invalid_usage;
exit
fi
# attempt upload
if [ ! "$clipboard" ]; then
echo -n "Attempting upload "
fi
autoload -U zfinit
zfinit
zfopen "$ftp_host/$ftp_path_prefix/$ftp_upload_path" "$ftp_user" "$ftp_pass"
for i in "$@"; do
if [ ! -e "$i" ]; then
echo "Error: '$i' doesn't exist (ignored)"
elif [ -d "$i" ]; then
zfput -r $i
else
zfput "$i"
fi
done
if [ ! "$clipboard" ]; then
zfstat -v
fi
zfclose