1
#!/usr/local/bin/expect
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
11
# http://www.apache.org/licenses/LICENSE-2.0
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.
19
#--------------------------------------------------------------------------
22
# derived from: supportmode.exp
24
# This script downloads a file from remote ftp host.
27
#--------------------------------------------------------------------------
32
set script_name "ftp.exp"
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"
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"
49
proc ftp {host dir name mode user password} {
53
# default 10 second timeout
62
send_user "\[Error\] ftp session timed-out waiting for name\n"
71
send_user "\[Error\] ftp session timed-out waiting for password\n"
80
send_user "\[Error\] ftp session timed-out waiting for ftp prompt\n"
91
send_user "\[Error\] ftp session timed-out while changing dir\n"
97
# turn interactive mode off
102
send_user "\[Error\] ftp session timed-out while changing interactive mode\n"
113
send_user "\[Error\] ftp session timed-out while setting mode\n"
119
# set timeout to 10 min for transferring all files
127
send_user "\[Error\] ftp session timed-out during get\n"
139
#--------------------------------------------------------------------------
141
#--------------------------------------------------------------------------
153
while {[llength $argv]>0} {
154
set flag [lindex $argv 0]
155
switch -- $flag "-h" {
159
set argv [lrange $argv 1 end]
160
set ftp_host [lindex $argv 0]
162
set argv [lrange $argv 1 end]
164
set argv [lrange $argv 1 end]
165
set ftp_dir [lindex $argv 0]
167
set argv [lrange $argv 1 end]
169
set argv [lrange $argv 1 end]
170
set ftp_fn [lindex $argv 0]
172
set argv [lrange $argv 1 end]
174
set argv [lrange $argv 1 end]
175
set ftp_mode [lindex $argv 0]
177
set argv [lrange $argv 1 end]
179
set argv [lrange $argv 1 end]
180
set ftp_usr [lindex $argv 0]
182
set argv [lrange $argv 1 end]
184
set argv [lrange $argv 1 end]
185
set ftp_pw [lindex $argv 0]
187
set argv [lrange $argv 1 end]
193
# do we need some help?
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