1if [ ! "$_MEDIA_FTP_SUBR" ]; then _MEDIA_FTP_SUBR=1
2#
3# Copyright (c) 2012-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
--- 10 unchanged lines hidden (view full) ---
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/ftp.subr 253333 2013-07-14 03:08:52Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/ftp.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr
--- 746 unchanged lines hidden (view full) ---
782 break # to failure
783 done
784
785 unset FTP_INITIALIZED $VAR_FTP_PATH
786 f_device_network_down $dev
787 return $FAILURE
788}
789
790# f_media_get_ftp $device $file [$probe_type]
791#
792# Returns data from $file on an FTP server using ftp(1). Please note that
793# $device is unused but must be present (even if null). Information is instead
794# gathered from the environment. If $probe_type is present and non-NULL,
795# returns success if $file exists. If $probe_type is equal to $PROBE_SIZE,
796# prints the size of $file in bytes to standard-out.
797#
798# Variables from variable.subr used to configure the connection are as follows
799# (all of which are configured by f_media_set_ftp above):
800#
801# VAR_FTP_HOST
802# FTP host to connect to. Can be an IPv4 address, IPv6 address,
803# or DNS hostname of your choice.
804# VAR_FTP_PORT
--- 17 unchanged lines hidden (view full) ---
822# See variable.subr for additional information.
823#
824# Example usage:
825# f_media_set_ftp
826# f_media_get_ftp media $file
827#
828f_media_get_ftp()
829{
830 local dev="$1" file="$2" probe_type="$3" hosts=
831
832 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_type=%s" \
833 "$dev" "$file" "$probe_type"
834
835 local ftp_host ftp_port
836 f_getvar $VAR_FTP_HOST ftp_host
837 f_getvar $VAR_FTP_PORT ftp_port
838
839 if [ ! "$FTP_INITIALIZED" ]; then
840 f_dprintf "No FTP connection open, can't get file %s" "$file"
841 return $FAILURE
--- 53 unchanged lines hidden (view full) ---
895 f_getvar $VAR_FTP_DIR\#/ dir
896 f_getvar $VAR_FTP_STATE mode
897
898 local port="${ftp_port:+:$ftp_port}"
899 case "$host" in *:*) host="[$host]"; esac
900
901 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
902
903 if [ "$probe_type" ]; then
904 local url="ftp://$userpass$host$port/$dir/$file" size
905 [ "$use_anon" ] && url="ftp://$host$port/$dir/$file"
906 if ! size=$( fetch -s "$url" 2>&1 ) || ! f_isinteger "$size"
907 then
908 f_dprintf "request failed! size response=[%s]" "$size"
909 [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
910 return $FAILURE
911 fi
912 [ "$probe_type" = "$PROBE_SIZE" ] && echo "$size"
913 return $SUCCESS
914 fi
915
916 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
917 ftp -V ${use_anon:+-a} -o - \
918 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null
919 local retval=$?
920
--- 21 unchanged lines hidden ---
2#
3# Copyright (c) 2012-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
--- 10 unchanged lines hidden (view full) ---
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/ftp.subr 253333 2013-07-14 03:08:52Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/ftp.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr
--- 746 unchanged lines hidden (view full) ---
782 break # to failure
783 done
784
785 unset FTP_INITIALIZED $VAR_FTP_PATH
786 f_device_network_down $dev
787 return $FAILURE
788}
789
790# f_media_get_ftp $device $file [$probe_type]
791#
792# Returns data from $file on an FTP server using ftp(1). Please note that
793# $device is unused but must be present (even if null). Information is instead
794# gathered from the environment. If $probe_type is present and non-NULL,
795# returns success if $file exists. If $probe_type is equal to $PROBE_SIZE,
796# prints the size of $file in bytes to standard-out.
797#
798# Variables from variable.subr used to configure the connection are as follows
799# (all of which are configured by f_media_set_ftp above):
800#
801# VAR_FTP_HOST
802# FTP host to connect to. Can be an IPv4 address, IPv6 address,
803# or DNS hostname of your choice.
804# VAR_FTP_PORT
--- 17 unchanged lines hidden (view full) ---
822# See variable.subr for additional information.
823#
824# Example usage:
825# f_media_set_ftp
826# f_media_get_ftp media $file
827#
828f_media_get_ftp()
829{
830 local dev="$1" file="$2" probe_type="$3" hosts=
831
832 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_type=%s" \
833 "$dev" "$file" "$probe_type"
834
835 local ftp_host ftp_port
836 f_getvar $VAR_FTP_HOST ftp_host
837 f_getvar $VAR_FTP_PORT ftp_port
838
839 if [ ! "$FTP_INITIALIZED" ]; then
840 f_dprintf "No FTP connection open, can't get file %s" "$file"
841 return $FAILURE
--- 53 unchanged lines hidden (view full) ---
895 f_getvar $VAR_FTP_DIR\#/ dir
896 f_getvar $VAR_FTP_STATE mode
897
898 local port="${ftp_port:+:$ftp_port}"
899 case "$host" in *:*) host="[$host]"; esac
900
901 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
902
903 if [ "$probe_type" ]; then
904 local url="ftp://$userpass$host$port/$dir/$file" size
905 [ "$use_anon" ] && url="ftp://$host$port/$dir/$file"
906 if ! size=$( fetch -s "$url" 2>&1 ) || ! f_isinteger "$size"
907 then
908 f_dprintf "request failed! size response=[%s]" "$size"
909 [ "$probe_type" = "$PROBE_SIZE" ] && echo "-1"
910 return $FAILURE
911 fi
912 [ "$probe_type" = "$PROBE_SIZE" ] && echo "$size"
913 return $SUCCESS
914 fi
915
916 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
917 ftp -V ${use_anon:+-a} -o - \
918 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null
919 local retval=$?
920
--- 21 unchanged lines hidden ---