From e7f29cac778f558ca2eaf405827ef8aef32c8892 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 10 Sep 1999 13:58:19 +0000 Subject: Initial revision --- Functions/Zftp/zffcache | 24 ++++++++++++++++ Functions/Zftp/zfsession | 71 +++++++++++++++++++++++++++++++++++++++++++++++ Functions/Zftp/zftransfer | 62 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 Functions/Zftp/zffcache create mode 100644 Functions/Zftp/zfsession create mode 100644 Functions/Zftp/zftransfer (limited to 'Functions') diff --git a/Functions/Zftp/zffcache b/Functions/Zftp/zffcache new file mode 100644 index 000000000..0d9686660 --- /dev/null +++ b/Functions/Zftp/zffcache @@ -0,0 +1,24 @@ +# Generate an array name for storing the cache for the current session, +# storing it in fcache_name, then generate the cache for the current +# directory, or with argument -d clear the cache. + +fcache_name=$zfconfig[fcache_$ZFTP_SESSION] +if [[ -z $fcache_name ]]; then + local vals + vals=(${(v)zfconfig[(I)fcache_*]##zftp_fcache_}) + integer i + while [[ -n ${vals[(r)zftp_fcache_$i]} ]]; do + (( i++ )) + done + fcache_name=zftp_fcache_$i + zfconfig[fcache_$ZFTP_SESSION]=$fcache_name +fi + +if [[ $1 = -d ]]; then + unset $fcache_name +elif (( ${(P)#fcache_name} == 0 )); then + local tmpf=${TMPPREFIX}zffcache$$ + zftp ls >$tmpf + eval "$fcache_name=(\${(f)\"\$(<\$tmpf)\"})" + rm -f $tmpf +fi diff --git a/Functions/Zftp/zfsession b/Functions/Zftp/zfsession new file mode 100644 index 000000000..9cd0d918f --- /dev/null +++ b/Functions/Zftp/zfsession @@ -0,0 +1,71 @@ +# function zfsession { +# Change or list the sessions for the current zftp connection. + +emulate -L zsh + +local opt opt_l opt_v opt_o opt_d hadopts + +while getopts ":lovd" opt; do + [[ $opt = "?" ]] && print "zfsession: bad option: -$OPTARG" >&2 && return 1 + eval "opt_$opt=1" + hadopts=1 +done +(( OPTIND > 1 )) && shift $(( OPTIND - 1 )) + +if [[ $# -gt 1 || (( -n $hadopts && -z $opt_d ) && $# -gt 0 ) ]] +then + print "Usage: zfsession ( [ -lvod ] | session )" 1>&2 + return 1 +fi + +if [[ -n $opt_v ]]; then + local sess + for sess in $(zftp session); do + print -n "${(r.15.. ..:.)sess}\t${zfconfig[lastloc_$sess]:-not connected}" + if [[ $sess = $ZFTP_SESSION ]]; then + print " *" + else + print + fi + done +elif [[ -n $opt_l ]]; then + zftp session +fi + +if [[ -n $opt_o ]]; then + if [[ $zfconfig[lastsession] != $ZFTP_SESSION ]]; then + local cursession=$ZFTP_SESSION + zftp session $zfconfig[lastsession] + zfconfig[lastsession]=$cursession + print $ZFTP_SESSION + else + print "zfsession: no previous session." >&2 + return 1 + fi +fi + +if [[ -n $opt_d ]]; then + local del=${1:-$ZFTP_SESSION} key + key=${zfconfig[fcache_$del]} + [[ -n $key ]] && unset $key + for key in fcache lastloc lastdir curdir otherdir otherargs lastuser; do + unset "zfconfig[${key}_${del}]" + done + zftp rmsession $del + return +fi + +[[ -n $hadopts ]] && return $stat + +if [[ $# = 0 ]]; then + print $ZFTP_SESSION + return +fi + +local oldsession=${ZFTP_SESSION:-default} +zftp session $1 +if [[ $ZFTP_SESSION != $oldsession ]]; then + zfconfig[lastsession]=$oldsession + zftp_chpwd +fi +# } 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 +# } -- cgit 1.4.1