comparison bin/xcp @ 0:2aa53823fb21

new repo
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sat, 06 Jun 2026 10:19:04 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:2aa53823fb21
1 #!/usr/bin/bash
2 usage=$'xcp host:[dir] files... [-r newName] # down
3 or
4 xcp files... [-r newName] host:[dir] # up
5 -r will rename the file after transfer, must be only one file!
6 dir is either absolute or will start from home'
7 case $1 in
8 -*|'') echo "$usage" 1>&2; exit 1;;
9 esac
10 case "$1" in
11 *:*)
12 remote="$1"; shift
13 download=1
14 ;;
15 esac
16 if [ "$remote" ] ; then
17 bb=$(($# - 1))
18 if [ "${!bb}" = "-r" ]; then
19 newname=${!#}
20 set -- "${@: 1: $#-2}"
21 if [ $# -ne 1 ]; then
22 echo "one file only allowed with rename!" "$@" 1>&2
23 exit 3
24 fi
25 fi
26 else
27 case "${!#}" in
28 *:*) remote="${!#}"
29 set -- "${@: 1: $#-1}"
30 bb=$(($# - 1))
31 if [ "${!bb}" = "-r" ]; then
32 newname=${!#}
33 set -- "${@: 1: $#-2}"
34 if [ $# -ne 1 ]; then
35 echo "one file only allowed with rename!" "$@" 1>&2
36 exit 3
37 fi
38 fi
39 ;;
40 *) echo "no remote spec.???" 1>&2; echo $usage 1>&2; exit 2;;
41 esac
42 fi
43 IFS=: read host dir < <(echo "$remote")
44 cd="set cmd:fail-exit true; "
45 if [ "$dir" ] ; then
46 cd="${cd}cd \"$dir\"; "
47 fi
48 if [ "$download" ] ; then
49 # get files from host
50 if [ "$newname" ] ; then
51 doit="${cd}get $(printf \ \'%s\' "$@") -o '$newname'; quit"
52 else
53 doit="${cd}mget $(printf \ \'%s\' "$@"); quit"
54 fi
55 else
56 # put files to host
57 if [ "$newname" ] ; then
58 doit="${cd}put $(printf \ \'%s\' "$@") -o '$newname'; quit"
59 else
60 doit="${cd}mput $(printf \ \'%s\' "$@"); quit"
61 fi
62 fi
63
64 echo lftp -e "$doit" sftp://${host}: 1>&2
65 lftp -e "$doit" sftp://${host}:
66 res="$?"
67 if [ "$res" = 0 ]
68 then
69 echo success
70 else
71 echo failed: $res
72 fi
73