-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqnet-ftp.src
201 lines (176 loc) · 4.13 KB
/
qnet-ftp.src
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# qnet-ftp.src
# $Id: qnet-ftp.src,v 1.11 2009/11/02 06:26:03 rswindell Exp $
# @format.tab-size 8, @format.use-tabs true
###############################################################################
# Baja module for performing FTP-based QWKnet call-outs #
# Requires Synchronet v3.00d and Baja v2.30 #
# Developed 2001 by Rob Swindell #
###############################################################################
# Usage: *QNET-FTP HUBID ADDRESSS PASSWORD port
# Example: *QNET-FTP VERT vert.synchro.net YOURPASS 21
# You may use the qnet-ftp.bin module INSTEAD of your normal ftp/script
# QWKnet call-out routine (exec/vert.bat). You can do this by changing
#
# SCFG->Networks->QWK->Hubs->VERT->Call-out Command Line to:
#
# *QNET-FTP VERT vert.synchro.net YOURPASS port
#
# if you leave the port value blank, this script will default to port 21
#
# The asterisk is important! YOURPASS is your QWKnet password here on Vertrauen.
#
# No modification or recompilation of this module should be necessary.
#
# Updated on Feb 7th, 2007 to support non standard ftp ports
# -- Lloyd Hannesson [email protected]
!include sbbsdefs.inc
!include file_io.inc
# Must be FIRST function call (or module will immediately terminate)
set _online ON_LOCAL
# Variables
int i argc argv sock port flen
str tmp rep qwk hubid addr user password portstr
str cmdline
set _ftp_mode FTP_PASV
# Process command line arguments
set hubid ""
set addr ""
set password ""
set portstr ""
set port 0
# Display command line
copy cmdline str
lprintf "QNET-FTP: %s" cmdline
set argc 0
:process_args
compare_str ""
if_true
goto end_args
end_if
sprintf tmp "%.1s" str
shift_str 1
compare tmp " "
if_true
add argc 1
goto process_args
end_if
switch argc
case 0
strcat hubid tmp
end_case
case 1
strcat addr tmp
end_case
case 2
strcat password tmp
end_case
case 3
strcat portstr tmp
end_case
default
goto usage
end_switch
goto process_args
:usage
lprintf "QNET-FTP: !INCORRECT USAGE: %s" cmdline
return
:end_args
compare hubid ""
if_true
goto usage
end_if
compare addr ""
if_true
goto usage
end_if
compare password ""
if_true
goto usage
end_if
copy port portstr
compare port 0
if_true
# if no Port is passed on the command line, default to 21
set port 21
end_if
sprintf rep "%%j%s.rep" hubid
sprintf qwk "%%j%s.qwk" hubid
chkfile qwk
if_true
lprintf "QNET-FTP: %s already exists!" qwk
set i 0
:check_qwk
sprintf qwk "%%j%s.qw%ld" hubid i
chkfile qwk
if_true
lprintf "QNET-FTP: %s already exists!" qwk
add i 1
compare i 10
if_equal
goto exit
end_if
goto check_qwk
end_if
end_if
socket_open sock
if_false
lprintf "QNET-FTP: !socket_open failure socket_error=%d" _socket_error
goto exit
end_if
lprintf "QNET-FTP: Connecting to %s:%u ... " addr port
socket_connect sock addr port
crlf
if_false
lprintf "QNET-FTP: !socket_connect failed socket_error=%d" _socket_error
goto exit
end_if
lprintf "QNET-FTP: Connected to %s" addr
set user "%q"
lprintf "QNET-FTP: Logging in as '%s' (PW: '%s')" user password
ftp_login sock user password
if_false
lprintf "QNET-FTP: !ftp_login failed socket_error=%d" _socket_error
goto exit
end_if
lprintf "QNET-FTP: Logged in successfully"
chkfile rep
if_true
###################
# Send REP packet #
###################
lprintf "QNET-FTP: Sending REP packet: %s" rep
sprintf str "%s.rep" hubid
ftp_put sock rep str
if_false
lprintf "QNET-FTP: !ftp_put failed socket_error=%d\r\n" _socket_error
else
lprintf "QNET-FTP: REP packet sent successfully"
remove_file rep
end_if
end_if
#######################
# Download QWK packet #
#######################
sprintf str "%s.qwk" hubid
lprintf "QNET-FTP: Downloading QWK Packet: %s" str
ftp_get sock str qwk
if_true
get_file_length flen qwk
compare flen 0
if_equal
lprintf "QNET-FTP: Downloaded 0-byte %s" qwk
remove_file qwk
else
lprintf "QNET-FTP: Downloaded %s successfully" str
end_if
else
lprintf "QNET-FTP: %s NOT downloaded socket_error=%d (no new messages?)" str _socket_error
remove_file qwk
end_if
ftp_logout sock
#################
# Exit routine #
#################
:exit
lprintf "QNET-FTP: Done."
# End of QNET-FTP.SRC