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 252987 2013-07-07 18:51:44Z 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_only]
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_only is present and non-NULL,
795# returns success if $file exists.
796#
797# Variables from variable.subr used to configure the connection are as follows
798# (all of which are configured by f_media_set_ftp above):
799#
800# VAR_FTP_HOST
801# FTP host to connect to. Can be an IPv4 address, IPv6 address,
802# or DNS hostname of your choice.
803# VAR_FTP_PORT
--- 17 unchanged lines hidden (view full) ---
821# See variable.subr for additional information.
822#
823# Example usage:
824# f_media_set_ftp
825# f_media_get_ftp media $file
826#
827f_media_get_ftp()
828{
829 local dev="$1" file="$2" probe_only="$3" hosts=
830
831 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_only=%s" \
832 "$dev" "$file" "$probe_only"
833
834 local ftp_host ftp_port
835 f_getvar $VAR_FTP_HOST ftp_host
836 f_getvar $VAR_FTP_PORT ftp_port
837
838 if [ ! "$FTP_INITIALIZED" ]; then
839 f_dprintf "No FTP connection open, can't get file %s" "$file"
840 return $FAILURE
--- 53 unchanged lines hidden (view full) ---
894 f_getvar $VAR_FTP_DIR\#/ dir
895 f_getvar $VAR_FTP_STATE mode
896
897 local port="${ftp_port:+:$ftp_port}"
898 case "$host" in *:*) host="[$host]"; esac
899
900 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
901
902 if [ "$probe_only" ]; then
903 local url="ftp://$userpass$host$port/$dir/$file"
904 [ "$use_anon" ] && url="ftp://$host$port/$dir/$file"
905 if ! size=$( fetch -s "$url" 2>&1 ) || ! f_isinteger "$size"
906 then
907 f_dprintf "request failed! size response=[%s]" "$size"
908 return $FAILURE
909 fi
910 return $SUCCESS
911 fi
912
913 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
914 ftp -V ${use_anon:+-a} -o - \
915 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null
916 local retval=$?
917
--- 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 252987 2013-07-07 18:51:44Z 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_only]
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_only is present and non-NULL,
795# returns success if $file exists.
796#
797# Variables from variable.subr used to configure the connection are as follows
798# (all of which are configured by f_media_set_ftp above):
799#
800# VAR_FTP_HOST
801# FTP host to connect to. Can be an IPv4 address, IPv6 address,
802# or DNS hostname of your choice.
803# VAR_FTP_PORT
--- 17 unchanged lines hidden (view full) ---
821# See variable.subr for additional information.
822#
823# Example usage:
824# f_media_set_ftp
825# f_media_get_ftp media $file
826#
827f_media_get_ftp()
828{
829 local dev="$1" file="$2" probe_only="$3" hosts=
830
831 f_dprintf "f_media_get_ftp: dev=[%s] file=[%s] probe_only=%s" \
832 "$dev" "$file" "$probe_only"
833
834 local ftp_host ftp_port
835 f_getvar $VAR_FTP_HOST ftp_host
836 f_getvar $VAR_FTP_PORT ftp_port
837
838 if [ ! "$FTP_INITIALIZED" ]; then
839 f_dprintf "No FTP connection open, can't get file %s" "$file"
840 return $FAILURE
--- 53 unchanged lines hidden (view full) ---
894 f_getvar $VAR_FTP_DIR\#/ dir
895 f_getvar $VAR_FTP_STATE mode
896
897 local port="${ftp_port:+:$ftp_port}"
898 case "$host" in *:*) host="[$host]"; esac
899
900 f_dprintf "sending ftp request for: %s" "ftp://$host$port/$dir/$file"
901
902 if [ "$probe_only" ]; then
903 local url="ftp://$userpass$host$port/$dir/$file"
904 [ "$use_anon" ] && url="ftp://$host$port/$dir/$file"
905 if ! size=$( fetch -s "$url" 2>&1 ) || ! f_isinteger "$size"
906 then
907 f_dprintf "request failed! size response=[%s]" "$size"
908 return $FAILURE
909 fi
910 return $SUCCESS
911 fi
912
913 eval FTPMODE=\"\$mode\" ${use_anon:+FTPANONPASS=\"\$pass\"} \
914 ftp -V ${use_anon:+-a} -o - \
915 \"ftp://\$userpass\$host\$port/\$dir/\$file\" 2> /dev/null
916 local retval=$?
917
--- 21 unchanged lines hidden ---