about summary refs log tree commit diff
path: root/Functions/Zftp/zftransfer
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-09-10 13:57:31 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-09-10 13:57:31 +0000
commitb67e4abb100f67ca05809baab37700eb5ee0a342 (patch)
treef19c7eb1544bd6071e01155825a7aae3cc99117d /Functions/Zftp/zftransfer
parentbc3256997b737f6158e9768dcf5738a7c0fbb454 (diff)
downloadzsh-b67e4abb100f67ca05809baab37700eb5ee0a342.tar.gz
zsh-b67e4abb100f67ca05809baab37700eb5ee0a342.tar.xz
zsh-b67e4abb100f67ca05809baab37700eb5ee0a342.zip
manual/7767
Diffstat (limited to 'Functions/Zftp/zftransfer')
-rw-r--r--Functions/Zftp/zftransfer62
1 files changed, 62 insertions, 0 deletions
diff --git a/Functions/Zftp/zftransfer b/Functions/Zftp/zftransfer
new file mode 100644
index 000000000..929f099d2
--- /dev/null
+++ b/Functions/Zftp/zftransfer
@@ -0,0 +1,62 @@
+# function zftransfer {
+# Transfer files between two distinct sessions. No remote globbing
+# is done, since only single pairs can be transferred.
+
+emulate -L zsh
+
+local sess1 sess2 file1 file2 oldsess=${ZFTP_SESSION}
+
+if [[ $# -ne 2 ]]; then
+  print "Usage: zftransfer sess1:file1 sess2:file2" 1>&2
+  return 1
+fi
+
+if [[ $1 = *:* ]]; then
+  sess1=${1%%:*}
+  file1=${1#*:}
+fi
+: ${sess1:=$ZFTP_SESSION}
+
+if [[ $2 = *:* ]]; then
+  sess2=${2%%:*}
+  file2=${2#*:}
+fi
+: ${sess2:=$ZFTP_SESSION}
+if [[ -z $file2 || $file2 = */ ]]; then
+  file2="${file2}${file1:t}"
+fi
+
+if [[ $sess1 = $sess2 ]]; then
+  print "zftransfer: must use two distinct sessions." 1>&2
+  return 1
+fi
+
+zftp session $sess1
+zfautocheck || return 1
+
+# It's more useful to show the progress for the second part
+# of the pipeline, but unfortunately that can't necessarily get
+# the size from the pipe --- and if it does, it's probably wrong.
+# To avoid that, try to get the size and set it for the progress to
+# see.
+if [[ $zfconfig[progress] != none ]]; then
+  local ZFTP_TSIZE array tmpfile=${TMPPREFIX}zft$$
+  zftp remote $file1 >$tmpfile 2>/dev/null
+  array=($(<$tmpfile))
+  rm -f $tmpfile
+  [[ $#array -eq 2 ]] && ZFTP_TSIZE=$array[1]
+fi
+
+# We do the RHS of the pipeline in a subshell, too, so that
+# the LHS can get SIGPIPE when it exits.
+{ zfconfig[progress]=none
+  zftp get $file1 } |
+( zftp session $sess2
+  zfautocheck && zftp put $file2 )
+
+local stat=$?
+
+zftp session $oldsess
+
+return $stat
+# }