question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New method putDir

See original GitHub issue

Would be nice to have a method putDir:

sftp.putDir(localDirPath, remoteDirPath)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
serhiiboreikocommented, Jun 20, 2018

@luogao I found my very old helper function. I am not sure that I know how it works)

Helper:

const recursive = require('recursive-readdir');
const uniq = require('lodash/uniq');

const dirRegExp = /\/(.*\/|)(.*)$/g;

const putDir = (localDir, remoteDir, sftp) =>
  new Promise((resolve, reject) => {
    recursive(localDir, ['.DS_Store'])
      .then(files => (
        files
          .map(file => file.replace(localDir, ''))
          .map(file => file.replace(dirRegExp, `$1`))
          .filter(Boolean)
      ))
      .then(uniq)
      .then(dirs => Promise.all(
        dirs.map(dir => sftp.mkdir(`${remoteDir}/${dir}`, true))
      ))
      .then(() => recursive(localDir, ['.DS_Store']))
      .then(files => (
        files
          .map(file => file.replace(localDir, ''))
          .map(file => file.replace(dirRegExp, `$1`) + file.replace(dirRegExp, `$2`))
      ))
      .then(files => Promise.all(
        files.map(file => sftp.put(`${localDir}/${file}`, `${remoteDir}/${file}`))
      ))
      .then(resolve)
      .catch(err => reject(Error(err)));
  });

module.exports = { putDir  };

Usage:

putDir(localDirPath, remoteDirPath, sftp);
2reactions
serhiiboreikocommented, Sep 7, 2017

@jyu213 yes, put the dir with all files inside to the remote dir.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nike Method Putter Golf Clubs for sale - eBay
Get the best deals on Nike Method Putter Golf Clubs when you shop the ... NEW NIKE METHOD 002 PRECISION MILLED 303 35”...
Read more >
Nike Method Putters Reviews | Today's Golfer
The new Nike Method Concept Putter has the unusual appearance of a blade putter but with the technical performance of a mallet putter...
Read more >
New Nike Method Origin Putter - GOLF.com
Designed with input from Tiger Woods and McIlroy, the Method Origin is a classic blade packed with plenty of technology including the same...
Read more >
Nike Method 003 Putter - 2nd Swing Golf
The Nike 2010 Method Putter features Polymetal Groove Technology in a heel toe weighted putter to provide a high MOI and more forward...
Read more >
NIKE METHOD ORIGIN PUTTER REVIEW - YouTube
NIKE METHOD ORIGIN PUTTER REVIEWRick Shiels tests the new NIKE METHOD ORIGIN PUTTER at St Annes Old Links golf club and talks about...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found