diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-04-25 15:43:41 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-04-25 15:43:41 +0000 |
commit | 206237c8ec4b7619d9e70a75004cd1ae1066b0a0 (patch) | |
tree | ff703cbc295605f90755edb68672ed2de11f4a81 /Functions/Zftp/zfcget | |
parent | 8ceb54fbc2f879e0e80f58c18761bd54db07e5f7 (diff) | |
download | zsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.tar.gz zsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.tar.xz zsh-206237c8ec4b7619d9e70a75004cd1ae1066b0a0.zip |
zsh-3.1.5-pws-16 zsh-3.1.5-pws-16-w6109 dot-zsh-199904280524
Diffstat (limited to 'Functions/Zftp/zfcget')
-rw-r--r-- | Functions/Zftp/zfcget | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Functions/Zftp/zfcget b/Functions/Zftp/zfcget new file mode 100644 index 000000000..fd6accfed --- /dev/null +++ b/Functions/Zftp/zfcget @@ -0,0 +1,87 @@ +# function zfcget { +# Continuation get of files from remote server. +# For each file, if it's shorter here, try to get the remainder from +# over there. This requires the server to support the REST command +# in the way many do but RFC959 doesn't specify. +# 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. + +emulate -L zsh + +local loc rem stat=0 optlist opt nglob remlist locst remst +local tmpfile=${TMPPREFIX}zfcget$$ rstat tsize time + +while [[ $1 = -* ]]; do + if [[ $1 = - || $1 = -- ]]; then + shift; + break; + fi + optlist=${1#-} + for (( i = 1; i <= $#optlist; i++)); do + opt=$optlist[$i] + case $optlist[$i] in + G) nglob=1 + ;; + t) time=1 + ;; + *) print option $opt not recognised >&2 + ;; + esac + done + shift +done + +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=${rem:t} + if [[ ! -f $loc ]]; then + # File does not yet exist + zftp get $rem >$loc || stat=$? + else + # Compare the sizes. + locst=($(zftp local $loc)) + zftp remote $rem >$tmpfile + rstat=$? + remst=($(<$tmpfile)) + rm -f $tmpfile + if [[ $rstat = 2 ]]; then + print "Server does not support SIZE command.\n" \ + "Assuming you know what you're doing..." 2>&1 + zftp getat $rem $locst[1] >>$loc || stat=$? + continue + elif [[ $rstat = 1 ]]; then + print "Remote file not found: $rem" 2>&1 + continue + fi + if [[ $locst[1] -gt $remst[1] ]]; then + print "Local file is larger!" 2>&1 + continue; + elif [[ $locst[1] == $remst[1] ]]; then + print "Files are already the same size." 2>&1 + continue + else + if zftp getat $rem $locst[1] >>$loc; then + [[ $time = 1 ]] && zfrtime $loc $rem $remst[2] + else + stat=1 + fi + fi + fi + done + fi +done + +return $stat +# } |