-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkaon_hw4_ftp.sh
executable file
·97 lines (86 loc) · 1.77 KB
/
kaon_hw4_ftp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash -
#===============================================================================
#
# FILE: kaon_hw4_ftp.sh
#
# USAGE: ./kaon_hw4_ftp.sh
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Jeremy Johnson (), [email protected]
# Nasser Binshabeeb, [email protected]
# Trevor Orgill, [email protected]
# ORGANIZATION: WSU
# CREATED: 02/23/2017 12:46
# REVISION: ---
#===============================================================================
#set -o nounset # Treat unset variables as an error
# Usage information
usage() {
echo "Usage $0 -f <file> [-u <user> -p <passwd>] "
echo " -f The name of the file to upload"
echo " -u The FTP username"
echo " -p The FTP password"
exit 1
}
# Help parameter
if [[ $1 == "--help" ]]
then
usage
fi
# Get command-line options
while getopts ":f:u:p:" opt
do
case $opt in
f) file=$OPTARG
;;
u) user=$OPTARG
;;
p) passwd=$OPTARG
;;
# Checks for illegal options
\?) usage
exit 1
;;
esac
done
# Check for required arguments
if [[ -z $file ]]
then
usage
fi
# Determine if the user provided credentials
if [[ -z $user || -z $passwd ]]
then
echo "Anonymous"
user="anonymous"
passwd="anonymous"
dir="MockData"
else
echo "Credentials provided"
echo "Logging in as $user"
dir="~"
fi
# Transfer the file
# ftplog=`ftp -niv "137.190.19.91" <<EOT
ftp -niv "137.190.19.91" > ftp.log <<EOT
user $user $passwd
cd $dir
pwd
binary
put $file
quit
EOT
cat ftp.log
if [[ `grep "226 Transfer complete" ftp.log` ]]
then
echo "Transfer of $file successful"
else
echo "Transfer of $file failed"
exit 1
fi
exit 0