1
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2
# 2001, 2002, 2003 Free Software Foundation, Inc.
4
# This file is part of DejaGnu.
6
# DejaGnu is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# DejaGnu is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
# General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with DejaGnu; if not, write to the Free Software Foundation,
18
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
# Open an FTP connection to HOST.
22
proc ftp_open {host} {
26
if [board_info $host exists name] {
27
set host [board_info $host name]
30
if [board_info $host exists ftp_fileid] {
31
return [board_info $host ftp_fileid]
34
if [board_info $host exists hostname] {
35
set remotehost [board_info $host hostname]
40
# LoseQVT tends to get stuck sometimes; we'll loop around a few million
41
# times when it gets a "connection refused".
44
while {$spawn_id < 0 && $count >= 0} {
45
spawn ftp -n $remotehost
47
-i $spawn_id -re ".*220.*$prompt" { }
48
-i $spawn_id -re ".*Connection refused.*$prompt" {
50
send "open $remotehost\n"
53
-i $spawn_id default {
64
set board_info($host,ftp_fileid) $spawn_id
65
if [board_info $host exists ftp_username] {
66
if [board_info $host exists ftp_password] {
67
set command "user [board_info $host ftp_username] [board_info $host ftp_password]\n"
69
set command "user [board_info $host ftp_username]\n"
73
-i $spawn_id -re ".*230.*$prompt" { }
74
-i $spawn_id default {
82
send -i $spawn_id "binary\n"
84
-i $spawn_id -re "200.*$prompt" { }
85
-i $spawn_id timeout {
91
if [board_info $host exists ftp_directory] {
92
send "cd [board_info $host ftp_directory]\n"
94
-i $spawn_id -re "250.*$prompt" { }
95
-i $spawn_id default {
103
if [board_info $host exists ftp_no_passive] {
106
-i $spawn_id -re "Passive mode off.*$prompt" { }
107
-i $spawn_id -re "Passive mode on.*$prompt" {
111
-i $spawn_id -re ".*$prompt" { }
115
set board_info($host,ftp_fileid) $spawn_id
119
# Fetch REMOTEFILE from HOST and store it as LOCALFILE.
121
proc ftp_upload {host remotefile localfile} {
124
verbose "ftping $remotefile from $host to $localfile"
126
set spawn_id [ftp_open $host]
133
send -i $spawn_id "get $remotefile $localfile\n"
135
-i $spawn_id -re ".*Too many open files.*$prompt" {
138
-i $spawn_id -re ".*No such file or directory.*$prompt" {
142
-i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {set loop 0}
143
-i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
147
-i $spawn_id default {
152
set spawn_id [ftp_open $host]
161
# Download LOCALFILE to HOST as REMOTEFILE.
163
proc ftp_download {host localfile remotefile} {
166
verbose "putting $localfile $remotefile"
168
if [board_info $host exists hostname] {
169
set remotehost [board_info $host hostname]
174
set spawn_id [ftp_open $host]
181
send -i $spawn_id "put $localfile $remotefile\n"
183
-i $spawn_id -re ".*Too many open files.*$prompt" {
186
-i $spawn_id -re ".*No such file or directory.*$prompt" {
190
-re "(^|\[\r\n\])150.*connection for (.*) \[(\]\[0-9.,\]+\\)\[\r\n\]" {
191
set remotefile $expect_out(2,string)
194
-i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {
197
-i $spawn_id -re "Timeout.*$prompt" {
200
-i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
204
-i $spawn_id default {
209
set spawn_id [ftp_open $host]
218
# Close the FTP connection to HOST.
220
proc ftp_close {host} {
223
if [board_info $host exists name] {
224
set host [board_info $host name]
227
if ![board_info $host exists ftp_fileid] {
231
set spawn_id [board_info $host ftp_fileid]
232
unset board_info($host,ftp_fileid)
234
send -i $spawn_id "quit\n"