about summary refs log tree commit diff
path: root/Functions/Zftp/zfgcp
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-04-25 15:43:41 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-04-25 15:43:41 +0000
commit206237c8ec4b7619d9e70a75004cd1ae1066b0a0 (patch)
treeff703cbc295605f90755edb68672ed2de11f4a81 /Functions/Zftp/zfgcp
parent8ceb54fbc2f879e0e80f58c18761bd54db07e5f7 (diff)
downloadzsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.tar.gz
zsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.tar.xz
zsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.zip
Diffstat (limited to 'Functions/Zftp/zfgcp')
-rw-r--r--Functions/Zftp/zfgcp83
1 files changed, 83 insertions, 0 deletions
diff --git a/Functions/Zftp/zfgcp b/Functions/Zftp/zfgcp
new file mode 100644
index 000000000..26a08697d
--- /dev/null
+++ b/Functions/Zftp/zfgcp
@@ -0,0 +1,83 @@
+# function zfgcp {
+# ZFTP get as copy:  i.e. first arguments are remote, last is local.
+# Supposed to work exactly like a normal copy otherwise, i.e.
+#  zfgcp rfile lfile
+# or
+#  zfgcp rfile1 rfile2 rfile3 ... ldir
+# Options:
+#   -G   don't to remote globbing, else do
+#   -t   update the local file times to the same time as the remote.
+#        Currently this only works if you have the `perl' command,
+#        and that perl is version 5 with the standard library.
+#        See the function zfrtime for more gory details.
+#
+# If there is no current connection, try to use the existing set of open
+# parameters to establish one and close it immediately afterwards.
+
+emulate -L zsh
+
+local opt optlist nglob remlist rem loc time
+integer stat do_close
+
+while [[ $1 == -* ]]; do
+  if [[ $1 == - || $1 == -- ]]; then
+    shift;
+    break;
+  fi
+  optlist=${1#-}
+  for (( i = 1; i <= $#optlist; i++)); do
+    opt=$optlist[$i]
+    case $opt in
+      G) nglob=1
+	 ;;
+      t) time=1
+	 ;;
+      *) print option $opt not recognised >&2
+	 ;;
+    esac
+  done
+  shift
+done
+
+zfautocheck
+
+# hmm, we should really check this after expanding the glob,
+# but we shouldn't expand the last argument remotely anyway.
+if [[ $# -gt 2 && ! -d $argv[-1] ]]; then
+  print "zfgcp:  last argument must be a directory." 2>&1
+  return 1
+elif [[ $# == 1 ]]; then
+  print "zfgcp:  not enough arguments." 2>&1
+  return 1
+fi
+
+if [[ -d $argv[-1] ]]; then
+  local dir=$argv[-1]
+  argv[-1]=
+  for remlist in $*; do
+    # zfcd directory hack to put the front back to ~
+    if [[ $remlist = $HOME || $remlist = $HOME/* ]]; then
+      remlist="~${remlist#$HOME}"
+    fi
+    if [[ $nglob != 1 ]]; then
+      zfrglob remlist
+    fi
+    if (( $#remlist )); then
+      for rem in $remlist; do
+	loc=$dir/${rem:t}
+	if zftp get $rem >$loc; then
+	  [[ $time = 1 ]] && zfrtime $rem $loc
+	else
+	  stat=1
+	fi
+      done
+    fi
+  done
+else
+  zftp get $1 >$2 || stat=$?
+fi
+
+(( $do_close )) && zfclose
+
+return $stat
+# }