SFTP

Connect to the designated FTP/SFTP server to upload or download files

HOST

FTP/SFTP host, which can be an IP address or a hostname.

PORT

SSH host port number, the default value is 22.

USERNAME

User account name.

PASSWORD

Password for the account.

API

In addition to providing synchronous functions like api.files(), api.read(filename, encoding='utf8'), api.write(filename, text), api.rename(oldname, newname), and api.remove(filename) for accessing files within the workspace, the module also offers an FTP object and related asynchronous functions such as api.ftp.list(path), api.ftp.get(path, filename), api.ftp.put(filename, path), api.ftp.mkdir(path), api.ftp.rename(path, newpath), and api.ftp.remove(path) as follows:

// List files or subfolders in the server root directory
let entries = await api.ftp.list('/')
console.log(entries)

// Download the file located at the path /download/test.png on the server to the workspace, and name it as 'file1.png'
await api.ftp.get('/download/test.png', 'file1.png')

// Change the filename of the file located at the path /download/test.png on the server
await api.ftp.rename('/download/test.png', '/download/testnew.png')

// Upload the file 'file2.pdf' located in the workspace to the server path /upload/file2.pdf
await api.ftp.put('file2.pdf', '/upload/file2.pdf')

// Create a subdirectory on the server at the path /upload/temp
await api.ftp.mkdir('/upload/temp')

// Delete the file located at the server path /upload/file2.pdf
await api.ftp.remove('/upload/file2.pdf')

--

We are dedicated to improving our content. Please let us know if you come across any errors, including spelling, grammar, or other mistakes, as your feedback is valuable to us! 🤖️⚡️

Last updated