Perform actions like Download, Upload and Delete on the FTP server using REST API's.
FTP (File Transfer Protocol) is the protocol used to exchanges files between computers on the Internet.
FTP API is designed for people who need to perform actions like DOWNLOAD, UPLOAD, DELETE and transfer on the FTP server using REST API. SlashApi lets you control nearly all aspects of your FTP server operations programatically.
After you create an account and log in to the dashboard, choose FTP service on the collections page. To make FTP API you need to provide your FTP server credentials on the FTP creation form.
After you provide all the credentials above, click on the submit button and your FTP API is ready.
List all files in your FTP server
Parameter | Description |
---|---|
recursive | Operating on a directory and its contents, including the contents of any subdirectories |
directory | Directory root |
var axios = require('axios');
var config = {
method: 'get',
url: 'http://v1.slashapi.com/slashapi/ftp/u2nyrJqa0f/files?directory=your-directory'
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
List all directories in your FTP server
Parameter | Description |
---|---|
recursive | Operating on a directory and its contents, including the contents of any subdirectories |
directory | Directory root |
var axios = require('axios');
var config = {
method: 'get',
url: 'http://v1.slashapi.com/slashapi/ftp/u2nyrJqa0f/directories?directory=your-directory'
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Download File from your FTP server
Parameter | Description |
---|---|
path | [required] Path to file |
var axios = require('axios');
var config = {
method: 'get',
url: 'http://v1.slashapi.com/slashapi/ftp/u2nyrJqa0f/download?path=path-to-file'
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Upload File to your FTP server.
Body | Description |
---|---|
file | [required] File to upload |
directory | Destination directory for your uploaded file |
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('file', fs.createReadStream('/path/to/file'));
data.append('directory', 'target-directory');
var config = {
method: 'post',
url: 'http://v1.slashapi.com/slashapi/ftp/u2nyrJqa0f',
headers: {
...data.getHeaders()
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Delete Files in your FTP server
Body | Description |
---|---|
files | [required] Path to files. To delete multiple files, you can pass an array |
var axios = require('axios');
var data = JSON.stringify({
"files": [
"Directory/your-file.jpeg"
]
});
var config = {
method: 'delete',
url: 'http://v1.slashapi.com/slashapi/ftp/u2nyrJqa0f',
headers: {
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Delete directory in your FTP server
Body | Description |
---|---|
directory | [required] Target directory |
var axios = require('axios');
var data = JSON.stringify({
"directory": "target-directory"
});
var config = {
method: 'delete',
url: 'http://v1.slashapi.com/slashapi/ftp/u2nyrJqa0f',
headers: {
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});