Skip to content

Instantly share code, notes, and snippets.

@josemariagarcia95
Created November 9, 2018 11:13
Show Gist options
  • Save josemariagarcia95/250acdc8171c0e7b3d92d73cf361fd00 to your computer and use it in GitHub Desktop.
Save josemariagarcia95/250acdc8171c0e7b3d92d73cf361fd00 to your computer and use it in GitHub Desktop.
Code snippet to upload files to FTP server using Node.js
const Ftp = require( 'ftp' );
const ftpClient = new Ftp();
ftpClient.on( 'ready', function() {
ftpClient.put( './prueba.jpg', '/www/img/prueba.jpg', function( err, list ) {
if ( err ) throw err;
ftpClient.end();
} );
} );
ftpClient.connect( {
'host': '*****************',
'user': '***************',
'password': '**************'
} );
@emmyduruc
Copy link

i have tried this but it did not work

@josemariagarcia95
Copy link
Author

I have just tried it and it works, have you substituted the asterisks in the connect function for the correct values? Your server's URL, your user and password? Do you have a prueba.jpg file that the script can find?

@heydavee
Copy link

Worked great. Thanks for this handy snippet. 👋🏼

@alfiriel
Copy link

Helped a lot thank you!

@delaguila3787
Copy link

is there a way to make this work with esm 6 import sintax? because when i adapt it it shows an error that i can usea a constructor with ftpClient

@delaguila3787
Copy link

is there a way to make this work with esm 6 import sintax? because when i adapt it it shows an error that i can usea a constructor with ftpClient

hay alguna forma de hacerlo andar con ems 6? porque cuando lo adapto (import * as Ftp from "ftp") me da un error de que ftpClient no es un constructor

@lindalima
Copy link

lindalima commented Mar 24, 2023

Error: Cannot find module 'ftp'.
Is FTP not standard in nodejs?
I learned now, Node.js does not come with a built-in FTP module as part of its standard library.
Where do I find a third-party FTP modules?
I installed with "npm install basic-ftp"

@josemariagarcia95
Copy link
Author

Hi @lindalima,
The library is the one called ftp. The one you got ("basic-ftp") probably doesn't use the same syntax as this snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment