1# function zfrtime { 2# Set the modification time of file LOCAL to that of REMOTE. 3# If the optional TIME is passed, it should be in the FTP format 4# CCYYMMDDhhmmSS, i.e. no dot before the seconds, and in GMT. 5# This is what both `zftp remote' and `zftp local' return. 6# 7# Unfortunately, since the time returned from FTP is GMT and 8# your file needs to be set in local time, we need to do some 9# hacking around with time. 10 11emulate -L zsh 12zmodload zsh/datetime 13 14local time gmtime loctime year mon mday hr min sec y tmpdate 15local -i days_since_epoch 16 17if [[ -n $3 ]]; then 18 time=$3 19else 20 time=($(zftp remote $2 2>/dev/null)) 21 [[ -n $time ]] && time=$time[2] 22fi 23[[ -z $time ]] && return 1 24 25year=$time[1,4] 26mon=$time[5,6] 27mday=$time[7,8] 28hr=$time[9,10] 29min=$time[11,12] 30sec=$time[13,14] 31 32#count the number of days since epoch without the current day 33for y in {1970..$(( $year - 1))}; do 34 strftime -s tmpdate -r "%Y/%m/%d" ${y}/12/31 35 days_since_epoch+=$(strftime "%j" $tmpdate) 36done 37strftime -s tmpdate -r "%Y/%m/%d" $year/$mon/$(( $mday - 1 )) 38days_since_epoch+=$(strftime "%j" $tmpdate) 39# convert the time in number of seconds (this should be equivalent to timegm) 40time=$(( $sec + 60 * ( $min + 60 * ($hr + 24 * $days_since_epoch)) )) 41#Convert it back to CCYYMMDDhhmmSS 42strftime -s time "%Y%m%d%H%M%S" ${EPOCHSECONDS} 43touch -t ${time[1,12]}.${time[13,14]} $1 44