aboutsummaryrefslogtreecommitdiff
path: root/Functions/Zftp/zfcget
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Zftp/zfcget')
-rw-r--r--Functions/Zftp/zfcget87
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
+# }