This shows you the differences between two versions of the page.
Previous revision | |||
— | sdk:ftp2sms [2021/08/04 09:20] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Forward File Content of Files on FTP Server via SMS ====== | ||
+ | <code c ftp2sms.are> | ||
+ | printf(" | ||
+ | nb_syslog(' | ||
+ | SITE = " | ||
+ | |||
+ | USR = " | ||
+ | PWD = " | ||
+ | FTPINTERVAL = 30; | ||
+ | MAXSERVERITEMS = 100; | ||
+ | MAXSENTITEMS = 200; | ||
+ | ALARMNUMBER = " | ||
+ | |||
+ | // processed SMS | ||
+ | sentSMS = mkarray(); | ||
+ | |||
+ | // main | ||
+ | while (1) { | ||
+ | nb_syslog(" | ||
+ | nb_syslog(" | ||
+ | if (length(sentSMS) > MAXSENTITEMS) { | ||
+ | for (i = 0; i < length(sentSMS); | ||
+ | if (i < length(sentSMS)-MAXSENTITEMS) { | ||
+ | nb_syslog(" | ||
+ | sentSMS[i] = (); // set oldest elements to void, i.e. delete them | ||
+ | } | ||
+ | } | ||
+ | sentSMS = array_compact(sentSMS); | ||
+ | nb_syslog(" | ||
+ | } | ||
+ | files = nb_transfer_list(USR, | ||
+ | |||
+ | if (files) { | ||
+ | if (length(files) > MAXSERVERITEMS) { | ||
+ | id = nb_sms_send(ALARMNUMBER, | ||
+ | } | ||
+ | filesarray = mkarray(); | ||
+ | for (i = 0; i < length(files); | ||
+ | file = files[i]; | ||
+ | filesarray[i] = file.name; | ||
+ | url = sprintf(" | ||
+ | path = "/ | ||
+ | if (nb_transfer_get(USR, | ||
+ | fp = fopen(path, " | ||
+ | if (fp) { | ||
+ | phonenumber = trim(fgets(fp)); | ||
+ | content = fread(fp, | ||
+ | // check new SMS | ||
+ | if (is_void(array_search(sentSMS, | ||
+ | // send SMS | ||
+ | id = nb_sms_send(phonenumber, | ||
+ | if (id) { | ||
+ | nb_syslog(" | ||
+ | sentSMS = array_merge(sentSMS, | ||
+ | nb_syslog(" | ||
+ | } else { | ||
+ | nb_syslog(" | ||
+ | } | ||
+ | } else { | ||
+ | nb_syslog(" | ||
+ | } | ||
+ | unlink(path); | ||
+ | } | ||
+ | else { | ||
+ | nb_syslog(" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } else { | ||
+ | nb_syslog(" | ||
+ | } | ||
+ | sleep(FTPINTERVAL); | ||
+ | } | ||
+ | exit(0); | ||
+ | </ | ||