-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSCP
90 lines (90 loc) · 1.83 KB
/
SCP
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
*
GIT.FILENAME = 'SCP'
GIT.REPO = 'https://github.com/Krowemoh/TCL-Utilities.git'
*
* VERSION
*
VERSION = '1'
*
@USER1 = 'SCP'
@USER2 = 'SCP'
*
EQU TRUE TO 1
EQU FALSE TO 0
*
CALL GET.ARGUMENTS(ARGUMENTS)
*
ARGS.LEN = DCOUNT(ARGUMENTS,@AM)
*
IF ARGS.LEN = 1 THEN
PRINT 'SCP - Upload and download files using scp'
PRINT
PRINT ' Send a file to a server:'
PRINT ' SCP {/path/to/file} {username:password@server[:port]:/path/to/file}'
PRINT
PRINT ' Get a file from a server:'
PRINT ' SCP {username:password@server[:port]:/path/to/file} {/path/to/file}'
PRINT
STOP
END
*
IF ARGS.LEN # 3 THEN
PRINT 'Invalid number of arguments.'
STOP
END
*
PATH.A = ARGUMENTS<2>
PATH.B = ARGUMENTS<3>
*
IF COUNT(PATH.A,':') > 1 THEN
LOCAL.PATH = PATH.B
*
URL = PATH.A
GOSUB PARSE.URL
*
DIRECTION = 'GET-FILE'
*
END ELSE IF COUNT(PATH.B,':') > 1 THEN
LOCAL.PATH = PATH.A
*
URL = PATH.B
GOSUB PARSE.URL
*
DIRECTION = 'SEND-FILE'
*
END ELSE
PRINT 'Invalid command - missing remote information.'
STOP
END
*
CALL SECURE.COPY(RESULTS,SERVER,USERNAME,PASSWORD,LOCAL.PATH,REMOTE.PATH,DIRECTION)
*
IF RESULTS = '' THEN
PRINT 'Successfully SCPed: ' : REMOTE.PATH
END ELSE
PRINT RESULTS
END
*
STOP
*
********************* S U B R O U T I N E *********************
*
PARSE.URL:NULL
*
U.POS = INDEX(URL,':',1)
USERNAME = URL[1,U.POS-1]
*
P.POS = INDEX(URL,'@',COUNT(URL,'@'))
PASSWORD = URL[U.POS+1,P.POS-U.POS-1]
*
SERVER.POS = INDEX(URL,':',COUNT(URL,':'))
SERVER = URL[P.POS+1,SERVER.POS-P.POS-1]
*
REMOTE.PATH = URL[SERVER.POS+1,999]
*
RETURN
*
* END OF PROGRAM
*
END
*