Reputation: 330
I want to upload file from my local machine to server using FTP in node js project. my project structure-
-media
-one.jpg
-two.jpg
-node_modules
-views
-index.js
my code -
client = new ftpClient(config, options);
client.connect(function () {
client.upload(['./media/five.png'], 'product', {
baseDir: 'test',
overwrite: 'older'
}, function (result) {
console.log(result);
});
});
I am getting this error- Error: The system cannot find the path specified.
if I am passing full url inspite of ./media/five.png
then I am getting this error-
Error: The parameter is incorrect.
how can I send my file to server?
please help
Thanks in advance
Upvotes: 0
Views: 943
Reputation: 290
as mentioned here https://www.npmjs.com/package/ftp-client
baseDir - local base path relative to the remote directory, e.g. if you want to upload file uploads/sample.js to public_html/uploads, baseDir has to be set to uploads
Moreover, your second parameter 'product' should be the path in the destination server If you want to upload file from your local 'media' directory to remote directory /product/media (assuming the 'product' directory is located at the root of the server) the parameters should look as follow:
client = new ftpClient(config, options);
client.connect(function () {
client.upload(['./media/five.png'], '/product/media', {
baseDir: 'media',
overwrite: 'older'
}, function (result) {
console.log(result);
});
});
Note: You should use the 'path' node module to join urls and path strings - https://nodejs.org/api/path.html
Upvotes: 1