~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/mgmt2/html2/agent-installer/ftp.exp

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/expect
 
2
 
 
3
#  Licensed to the Apache Software Foundation (ASF) under one
 
4
#  or more contributor license agreements.  See the NOTICE file
 
5
#  distributed with this work for additional information
 
6
#  regarding copyright ownership.  The ASF licenses this file
 
7
#  to you under the Apache License, Version 2.0 (the
 
8
#  "License"); you may not use this file except in compliance
 
9
#  with the License.  You may obtain a copy of the License at
 
10
#
 
11
#      http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
#  Unless required by applicable law or agreed to in writing, software
 
14
#  distributed under the License is distributed on an "AS IS" BASIS,
 
15
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
#  See the License for the specific language governing permissions and
 
17
#  limitations under the License.
 
18
 
 
19
#--------------------------------------------------------------------------
 
20
# ftp.exp
 
21
#
 
22
# derived from: supportmode.exp
 
23
#
 
24
# This script downloads a file from remote ftp host.
 
25
#
 
26
 
 
27
#--------------------------------------------------------------------------
 
28
 
 
29
exp_version -exit 5.0
 
30
 
 
31
# globals
 
32
set script_name "ftp.exp"
 
33
set debug 0
 
34
 
 
35
proc usage {} {
 
36
    global script_name
 
37
    send_user "\[Usage\] $script_name  \[-fh ftp-host\] \[-fd ftp-dir\] \[-fn ftp-file\] \[-fm ftp-mode\] \[-fu ftp-user\] \[-fp ftp-password\]\n"
 
38
    send_user "                 \[-h\]\n"
 
39
    send_user "        -fh        - ftp host\n"
 
40
    send_user "        -fd        - ftp directory\n"
 
41
    send_user "        -fn        - ftp file\n"
 
42
    send_user "        -fm        - ftp mode\n"
 
43
    send_user "        -fu        - ftp user id\n"
 
44
    send_user "        -fp        - ftp user password\n"
 
45
    send_user "        -h         - help (this screen)\n"
 
46
    exit
 
47
}
 
48
 
 
49
proc ftp {host dir name mode user password} {
 
50
 
 
51
    global debug 
 
52
 
 
53
    # default 10 second timeout
 
54
    set timeout 10
 
55
 
 
56
    spawn ftp $host
 
57
 
 
58
    # authenticate
 
59
    expect "Name*:" {
 
60
    } timeout {
 
61
        if ($debug) {
 
62
            send_user "\[Error\] ftp session timed-out waiting for name\n"
 
63
        }
 
64
        close
 
65
        return 0
 
66
    }
 
67
    send "$user\r"
 
68
    expect "Password:" {
 
69
    } timeout {
 
70
        if ($debug) {
 
71
            send_user "\[Error\] ftp session timed-out waiting for password\n"
 
72
        }
 
73
        close
 
74
        return 0
 
75
    }
 
76
    send "$password\r"
 
77
    expect "ftp>" {
 
78
    } timeout {
 
79
        if ($debug) {
 
80
            send_user "\[Error\] ftp session timed-out waiting for ftp prompt\n"
 
81
        }
 
82
        close
 
83
        return 0
 
84
    }
 
85
 
 
86
    # change directory
 
87
    send "cd $dir\r"
 
88
    expect "250*ftp>" {
 
89
    } timeout {
 
90
        if ($debug) {
 
91
            send_user "\[Error\] ftp session timed-out while changing dir\n"
 
92
        }
 
93
        close
 
94
        return 0
 
95
    }
 
96
 
 
97
    # turn interactive mode off
 
98
    send "prompt\r"
 
99
    expect "ftp>" {
 
100
    } timeout {
 
101
        if ($debug) {
 
102
            send_user "\[Error\] ftp session timed-out while changing interactive mode\n"
 
103
        }
 
104
        close
 
105
        return 0
 
106
    }
 
107
 
 
108
    # set mode
 
109
    send "$mode\r"
 
110
    expect "200*ftp>" {
 
111
    } timeout {
 
112
        if ($debug) {
 
113
            send_user "\[Error\] ftp session timed-out while setting mode\n"
 
114
        }
 
115
        close
 
116
        return 0
 
117
    }
 
118
 
 
119
    # set timeout to 10 min for transferring all files
 
120
    set timeout 600
 
121
 
 
122
    # get the file
 
123
    send "get $name\r"
 
124
    expect "ftp>" {
 
125
    } timeout {
 
126
        if ($debug) {
 
127
            send_user "\[Error\] ftp session timed-out during get\n"
 
128
        }
 
129
        close
 
130
        return 0
 
131
    }
 
132
 
 
133
    send "bye\r"
 
134
    close
 
135
    return 1
 
136
 
 
137
}
 
138
 
 
139
#--------------------------------------------------------------------------
 
140
# main() begins here
 
141
#--------------------------------------------------------------------------
 
142
 
 
143
set help 0
 
144
set mode_set 0
 
145
set ftp_host_set 0
 
146
set ftp_dir_set 0
 
147
set ftp_fn_set 0
 
148
set ftp_mode_set 0
 
149
set ftp_usr_set 0
 
150
set ftp_pw_set 0
 
151
 
 
152
# parse command args
 
153
while {[llength $argv]>0} {
 
154
    set flag [lindex $argv 0]
 
155
    switch -- $flag "-h" {
 
156
        set help 1
 
157
        break
 
158
    } "-fh" {
 
159
        set argv [lrange $argv 1 end]
 
160
        set ftp_host [lindex $argv 0]
 
161
        set ftp_host_set 1
 
162
        set argv [lrange $argv 1 end]
 
163
    } "-fd" {
 
164
        set argv [lrange $argv 1 end]
 
165
        set ftp_dir [lindex $argv 0]
 
166
        set ftp_dir_set 1
 
167
        set argv [lrange $argv 1 end]
 
168
    } "-fn" {
 
169
        set argv [lrange $argv 1 end]
 
170
        set ftp_fn [lindex $argv 0]
 
171
        set ftp_fn_set 1
 
172
        set argv [lrange $argv 1 end]
 
173
    } "-fm" {
 
174
        set argv [lrange $argv 1 end]
 
175
        set ftp_mode [lindex $argv 0]
 
176
        set ftp_mode_set 1
 
177
        set argv [lrange $argv 1 end]
 
178
    } "-fu" {
 
179
        set argv [lrange $argv 1 end]
 
180
        set ftp_usr [lindex $argv 0]
 
181
        set ftp_usr_set 1
 
182
        set argv [lrange $argv 1 end]
 
183
    } "-fp" {
 
184
        set argv [lrange $argv 1 end]
 
185
        set ftp_pw [lindex $argv 0]
 
186
        set ftp_pw_set 1
 
187
        set argv [lrange $argv 1 end]
 
188
    } default {
 
189
        break
 
190
    }
 
191
}
 
192
 
 
193
# do we need some help?
 
194
if {$help} {
 
195
    usage
 
196
}
 
197
 
 
198
if {($ftp_host_set) && ($ftp_dir_set) && ($ftp_fn_set) &&($ftp_mode_set) && ($ftp_usr_set) && ($ftp_pw_set)} {
 
199
    ftp $ftp_host $ftp_dir $ftp_fn $ftp_mode $ftp_usr $ftp_pw
 
200
}
 
201