-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqnet-ftp.js
84 lines (71 loc) · 2.23 KB
/
qnet-ftp.js
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
// $Id: qnet-ftp.js,v 1.3 2020/04/19 19:48:26 rswindell Exp $
//****************************************************************************
// JavaScript module for performing FTP-based QWKnet call-outs
// Inspired by exec/qnet-ftp.src
// Possible due to the load/ftp.js library developed by Deuce
//****************************************************************************
// Usage: ?qnet-ftp <hub-id> <address> <password> [port]
// Example: ?qnet-ftp VERT vert.synchro.net YOURPASS 21
const REVISION = "$Revision: 1.3 $".split(' ')[1];
require('ftp.js', 'FTP');
var username = system.qwk_id;
var hubid = argv[0];
var addr = argv[1];
var password = argv[2];
var port = argv[3] || 21;
var options = load({}, "modopts.js", "qnet-ftp:"+hubid);
if(!options)
options = load({}, "modopts.js", "qnet-ftp");
if(!options)
options = {};
var rep = system.data_dir + hubid + ".rep";
var qwk = hubid + ".qwk";
var qwk_fname = system.data_dir + qwk;
log(LOG_DEBUG, js.exec_file + " v" + REVISION);
if(file_getcase(qwk_fname)) {
alert(qwk_fname + " already exists");
for(var i = 0; ; i++) {
qwk_fname = system.data_dir + hubid + ".qw" + i;
if(!file_getcase(qwk_fname))
break;
alert(qwk_fname + " already exists");
if(i == 9)
exit(1);
}
}
var ftp;
try {
ftp = new FTP(addr, username, password, port, options.dataport, options.bindhost);
} catch(e) {
print("FTP Session with " + addr + " failed: " + e);
exit(1);
}
log(LOG_DEBUG, "Connected to " + addr + " via " + ftp.revision);
if(options.passive === false)
ftp.passive = false;
rep = file_getcase(rep);
if(rep) {
print("Sending REP Packet: " + rep + format(" (%1.1fKB)", file_size(rep) / 1024.0));
try {
ftp.stor(rep, file_getname(rep));
print("REP packet sent successfully");
file_remove(rep);
} catch(e) {
alert("Upload of " + rep + " failed: " + e);
exit(1);
}
}
print("Downloading QWK Packet: " + qwk);
try {
ftp.retr(qwk, qwk_fname);
if(file_size(qwk_fname) < 1) {
alert("Invalid QWK Packet size: " + file_size(qwk_fname));
file_remove(qwk_fname);
} else
print("Downloaded " + file_getname(qwk_fname)
+ format(" (%1.1fKB)", file_size(qwk_fname) / 1024.0) + " successfully");
} catch(e) {
alert("Download of " + qwk + " failed: " + e);
}
ftp.quit();
print("Done.");