about summary refs log tree commit diff
path: root/Functions/Zftp/zfput
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-12-15 21:33:36 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-12-15 21:33:36 +0000
commitce9d10e465acd5a5641778154d176fd737d47eed (patch)
tree4a82590f469b3eae8ffb3ab1d027406d6bad3f9e /Functions/Zftp/zfput
parent03e230cc54103d18e9c8a18208c7d27805400a71 (diff)
downloadzsh-ce9d10e465acd5a5641778154d176fd737d47eed.tar.gz
zsh-ce9d10e465acd5a5641778154d176fd737d47eed.tar.xz
zsh-ce9d10e465acd5a5641778154d176fd737d47eed.zip
zsh-workers/9067
Diffstat (limited to 'Functions/Zftp/zfput')
-rw-r--r--Functions/Zftp/zfput59
1 files changed, 52 insertions, 7 deletions
diff --git a/Functions/Zftp/zfput b/Functions/Zftp/zfput
index 0687163f0..ed81e8129 100644
--- a/Functions/Zftp/zfput
+++ b/Functions/Zftp/zfput
@@ -3,19 +3,64 @@
 # off any directory parts to get the remote filename (i.e. always
 # goes into current remote directory).  Use zfpcp to specify new
 # file name or new directory at remote end.
+#
+# -r means put recursively:  any directories encountered will have
+#    all their contents to arbitrary depth transferred.  Note that
+#    this creates the required directories.  Any files in subdirectories
+#    whose names begin with a `.' will also be included.
 
 emulate -L zsh
 
-local loc rem
-integer stat do_close
+[[ $curcontext = :zf*: ]] || local curcontext=:zfput:
+local opt opt_r
+integer stat do_close abort
+
+while getopts :r opt; do
+  [[ $opt = '?' ]] && print "zfget: bad option: -$OPTARG" && return 1
+  eval "opt_$opt=1"
+done
+(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
 
 zfautocheck
 
-for loc in $*; do
-  rem=${loc:t}
-  zftp put $rem <$loc
-  [[ $? == 0 ]] || stat=$?
-done
+zfput_sub() {
+  local subdirs loc rem
+  integer stat
+  subdirs=()
+
+  for loc in $*; do
+    if [[ -n $opt_r ]]; then
+      if [[ -d $loc ]]; then
+	subdirs=($subdirs $loc)
+	continue
+      else
+	rem=$loc
+      fi
+    else
+      rem=${loc:t}
+    fi
+
+    zftp put $rem <$loc
+    (( $? )) && stat=$?
+    if ! zftp test; then
+      abort=1
+      (( stat )) || stat=1
+      break;
+    fi
+  done
+
+  while (( $#subdirs  && ! abort )); do
+    zftp mkdir ${subdirs[1]}
+    zfput_sub ${subdirs[1]}/*(ND)
+    (( $? )) && stat=$?
+    shift subdirs
+  done
+
+  return $stat
+}
+
+zfput_sub $*
+stat=$?
 
 (( $do_close )) && zfclose