ftp.put()
ftp.put(addr,user,password,data,mode) → number
FTP File Write / Append
Write to a file on a ftp server.
Mode argument determines whether the file is overwritten or appended to.
Useful for uploading test results, etc to a remote server.
Testing
Run python3 -m pyftpdlib -w -p2121 -u logger -P secret on a local linux workstation to spin up a FTP server instance for testing
Requires installing pyftpdlib with pip install pyftpdlib or sudo apt-get install python3-pyftpdlib etc.
Security Considerations
FTP is considered an insecure file transfer protocol, use only on a private or restricted network.
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| address | string | yes | — | e.g. "10.0.0.1:21/log.txt" |
| user | string | optional | — | anonymous |
| password | string | optional | — | default = blank |
| data | string | yes | — | payload |
| mode | number | optional | 0 | 0 = write, 1 = append |
Returns
number
0 = success, >0 = error code
Example
while(run()){
let voltage = 14.5;
let msg = datetime().epoch.toFixed() + "\t" + voltage.toFixed(4) + "V"; // create a string with the epoch timestamp followed by the measurement value
// msg = 141312433142 13.6043V
let res = ftp.put("172.16.220.220:2121/voltage.log","logger","secret",msg,1); // append to the voltage.log file
print(res);
waitMS(5000); // log every 5 seconds
}