1 # Copyright
(C
) 1992-2019, 2020 Free Software Foundation
, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software
; you can redistribute it and
/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation
; either version
3 of the License
, or
8 #
(at your option
) any later version.
10 # DejaGnu is distributed in the hope that it will be useful
, but
11 # WITHOUT
ANY WARRANTY
; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License
for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu
; if not
, write to the Free Software Foundation
,
17 # Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
, MA
02110-1301, USA.
19 # Open an FTP connection to HOST.
21 proc ftp_open
{host
} {
25 if {[board_info $host
exists name]} {
26 set host
[board_info $host
name]
29 if {[board_info $host
exists ftp_fileid
]} {
30 return [board_info $host ftp_fileid
]
33 if {[board_info $host
exists hostname
]} {
34 set remotehost
[board_info $host hostname
]
39 # LoseQVT tends to
get stuck sometimes
; we
'll loop around a few million
40 # times when it gets a "connection refused".
43 while {$spawn_id < 0 && $count >= 0} {
44 spawn ftp -n $remotehost
46 -i $spawn_id -re ".*220.*$prompt" { }
47 -i $spawn_id -re ".*Connection refused.*$prompt" {
49 send "open $remotehost\n"
52 -i $spawn_id default {
63 set board_info($host,ftp_fileid) $spawn_id
64 if {[board_info $host exists ftp_username]} {
65 if {[board_info $host exists ftp_password]} {
66 set command "user [board_info $host ftp_username] [board_info $host ftp_password]\n"
68 set command "user [board_info $host ftp_username]\n"
72 -i $spawn_id -re ".*230.*$prompt" { }
73 -i $spawn_id default {
81 send -i $spawn_id "binary\n"
83 -i $spawn_id -re "200.*$prompt" { }
84 -i $spawn_id timeout {
90 if {[board_info $host exists ftp_directory]} {
91 send "cd [board_info $host ftp_directory]\n"
93 -i $spawn_id -re "250.*$prompt" { }
94 -i $spawn_id default {
102 if {[board_info $host exists ftp_no_passive]} {
105 -i $spawn_id -re "Passive mode off.*$prompt" { }
106 -i $spawn_id -re "Passive mode on.*$prompt" {
110 -i $spawn_id -re ".*$prompt" { }
114 set board_info($host,ftp_fileid) $spawn_id
118 # Fetch REMOTEFILE from HOST and store it as LOCALFILE.
120 proc ftp_upload {host remotefile localfile} {
123 verbose "ftping $remotefile from $host to $localfile"
125 set spawn_id [ftp_open $host]
132 send -i $spawn_id "get $remotefile $localfile\n"
134 -i $spawn_id -re ".*Too many open files.*$prompt" {
137 -i $spawn_id -re ".*No such file or directory.*$prompt" {
141 -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {set loop 0}
142 -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
146 -i $spawn_id default {
151 set spawn_id [ftp_open $host]
160 # Download LOCALFILE to HOST as REMOTEFILE.
162 proc ftp_download {host localfile remotefile} {
165 verbose "putting $localfile $remotefile"
167 if {[board_info $host exists hostname]} {
168 set remotehost [board_info $host hostname]
173 set spawn_id [ftp_open $host]
180 send -i $spawn_id "put $localfile $remotefile\n"
182 -i $spawn_id -re ".*Too many open files.*$prompt" {
185 -i $spawn_id -re ".*No such file or directory.*$prompt" {
189 -re {(^|[\r\n])150.*connection for (.*) [(][0-9.,]+\)[\r\n]} {
190 set remotefile $expect_out(2,string)
193 -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {
196 -i $spawn_id -re "Timeout.*$prompt" {
199 -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
203 -i $spawn_id default {
208 set spawn_id [ftp_open $host]
217 # Close the FTP connection to HOST.
219 proc ftp_close {host} {
222 if {[board_info $host exists name]} {
223 set host [board_info $host name]
226 if {![board_info $host exists ftp_fileid]} {
230 set spawn_id [board_info $host ftp_fileid]
231 unset board_info($host,ftp_fileid)
233 send -i $spawn_id "quit\n"