Use an FTP server inside a Spell
You can connect to an FTP server inside your Spell using the ftp-server
dependencies.
To add this dependency, click on Dependencies on the Spell editor and add basic-ftp
package:
You can also activate the fs
NodeJS API if you want to read and write files inside your /tmp
folder.
info
You must use the /tmp
folder to write and read files inside your Spell.
You have 512MB of storage per Spell and this storage is not persistent (all files are destroyed at the end).
If you want to store larger and persistent files, we recommend you to use File Storage APIs (like AWS S3)
Here is a code example to use basic-ftp
inside a Spell:
const client = new basic_ftp.Client();
try {
await client.access({
host: "",
user: 'user',
password: 'password',
secure: true
});
console.log(await client.list());
console.log(await client.downloadTo("/tmp/foo.txt", "foo.txt"));
try {
const data = fs.readFileSync('./foo.txt', 'utf8');
console.log(data);
} catch (err) {
console.error(err);
}
} catch (err) {
console.log(err.message);
} finally {
client.close();
}
Don't forget to close properly the FTP connection before the end of Spell