--- portunarchive.tcl.orig	2006-10-14 14:39:12.000000000 +0200
+++ portunarchive.tcl	2006-10-21 16:15:39.000000000 +0200
@@ -51,6 +51,7 @@
 default unarchive.post_args {}
 
 default unarchive.srcpath {${portarchivepath}}
+default unarchive.binhost {${portarchivebinhost}}
 default unarchive.type {}
 default unarchive.file {}
 default unarchive.path {}
@@ -63,6 +64,20 @@
 	global portname portversion portrevision portvariants portpath
 	global unarchive.srcpath unarchive.type unarchive.file unarchive.path
 
+	global fetch.user fetch.password fetch.use_epsv unarchive.binhost
+	global portverbose
+	set fetch_options {}
+	if {[string length ${fetch.user}] || [string length ${fetch.password}]} {
+		lappend fetch_options -u
+		lappend fetch_options "${fetch.user}:${fetch.password}"
+	}
+	if {${fetch.use_epsv} != "yes"} {
+		lappend fetch_options "--disable-epsv"
+	}
+	if {$portverbose == "yes"} {
+		lappend fetch_options "-v"
+	}
+
 	# Check mode in case archive called directly by user
 	if {[option portarchivemode] != "yes"} {
 		return -code error "Archive mode is not enabled!"
@@ -84,6 +99,10 @@
 	if {![string equal ${unarchive.srcpath} ${workpath}] && ![string equal ${unarchive.srcpath} ""]} {
 		set unarchive.srcpath [file join ${unarchive.srcpath} [option os.platform] [option os.arch]]
 	}
+	# Define achive binhost url
+	if {![string equal ${unarchive.binhost} ""]} {
+		set unarchive.binhost "${unarchive.binhost}/[option os.platform]/[option os.arch]"
+	}
 
 	# Determine if unarchive should be skipped
 	set skipped 0
@@ -109,7 +128,18 @@
 					set found 1
 					break
 				} else {
-					ui_debug "No [string toupper ${unarchive.type}] archive: ${unarchive.path}"
+					# file does not exist locally, we will try to download it from the binhost
+					set effectiveURL ""
+					set file_url "${unarchive.binhost}/${unarchive.file}"
+					ui_msg "$UI_PREFIX [format [msgcat::mc "Checking binhost for %s %s_%s%s"] $portname $portversion $portrevision $portvariants]"
+					if {![catch {eval curl fetch --effective-url effectiveURL $fetch_options {$file_url} ${unarchive.srcpath}/${unarchive.file}.TMP} result] &&
+						![catch {system "mv ${unarchive.srcpath}/${unarchive.file}.TMP ${unarchive.srcpath}/${unarchive.file}"}] } {
+						set found 1
+						break
+					} else {
+						ui_debug "No [string toupper ${unarchive.type}] archive: ${unarchive.path}"
+						exec rm -f ${unarchive.srcpath}/${unarchive.file}.TMP
+					}
 				}
 			} else {
 				ui_debug "Skipping [string toupper ${unarchive.type}] archive: $errmsg"

