title: Node js - ftp-srv - Simple ftp Server Example needed
body: <p>The last days I'm trying to get a simple ftp-server running in NodeJS.</p>
  <p>I found a package named &quot;ftp-srv&quot; with some documentation here:
  <a href="https://www.npmjs.com/package/ftp-srv" rel="nofollow noreferrer">https://www.npmjs.com/package/ftp-srv</a></p>
  <p>Inspire by the code-snipptes there I wrote a small script:</p>
  <pre><code>const FtpSrv = require ( 'ftp-srv' );
  
  const hostname = '0.0.0.0';
  const port = 1111
  
  const ftpServer = new FtpSrv ( 'ftp://' + hostname + ':' + port,
  { anonymous: true, greeting : [ &quot;Hello Jong&quot;, &quot;Wie gehts?&quot; ] } );
  
  ftpServer.on ( 'login', ( data, resolve, reject ) =&gt;
  {
    console.log ( 'data: '    + data );
    console.log ( 'resolve: ' + resolve );
    console.log ( 'reject: '  + reject );
  
  });
  
  ftpServer.on ( 'client-error', (connection, context, error) =&gt;
  {
    console.log ( 'connection: ' +  connection );
    console.log ( 'context: '    +  context );
    console.log ( 'error: '      +  error );
  });
  
  
  ftpServer.listen()
  .then(() =&gt;
  {
    console.log ( `Server running at http://${hostname}:${port}/` );
  });
  </code></pre>
  <p>I can start the Script with &quot;node ftpserver.js&quot; and it runs without a Problem.
  If I connect with a FTP-Client Software it seems to connect, but waits for the &quot;Welcome Message&quot; and hangs at that point.</p>
  <p>I provided the &quot;greeting&quot;-Variable but that text is not send to the client.</p>
  <p>I searched a lot in google but couldnt find any working Examples for &quot;ftp-srv&quot;.</p>
  <p>I think the point where I have to fill in some code is here:</p>
  <pre><code>ftpServer.on ( 'login', ( data, resolve, reject ) =&gt;
  {
    // HERE
  });
  </code></pre>
  <p>It would help me a lot if anyone could provide some Example-code to get a working client connection and to overcome the greeting message.</p>
  <p>--- Edit ---</p>
  <p>The Advice from jcaron helped a lot, Im one step further now. These are my changes:</p>
  <pre><code>[...]
  ftpServer.on ( 'login', ( data, resolve, reject ) =&gt;
  {
    resolve ( { root: '/home/peter/apps/ftpfiles' } );
  });
  [...]
  </code></pre>
  <p>When I connect with a client now, the client tries to read the remote directory. After 3 tries the client get a timeout.</p>
  <p>It seems like the client cant access the directory '/home/peter/apps/ftpfiles'. I can say that it exists and has read/write permissions by the user which I start my &quot;ftpserver.js&quot;-Script.</p>
  <p>I tried some things with a fs-object instead of root:[dir], but always see the same behaviour.</p>
  <p>Can anyone help?</p>
  <p>--- Edit ---</p>
  <p>In addition simply changed</p>
  <pre><code>const hostname = '0.0.0.0';
  #to local address:
  const hostname = '192.x.y.z';
  </code></pre>
  <p>and it worked for me.</p>