npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smb-enumerate-files

v1.0.4

Published

Enumeration of files on SMB shares for Node

Downloads

651

Readme

smb-enumerate-files

Enumeration of files on SMB shares for Node.js

This package allows easy file enumeration of SMB shared folders on a host machine. Useful to index or monitor an external machine. The implementation is focused on efficiency, both in time and network overhead.

Install

$ npm install smb-enumerate-files

Usage

enumerate(options)

Connects to an SMB share and retrieves the directory listing of the specified path. The options parameter take the following properties:

  • host (required) - The remote smb server's hostname or ip address
  • share (required) - The share to connect to on the host machine
  • path (optional) - The path on the share to retrieve the enumeration from. When omitted, the root directory of the share will be used. Slashes and backslashes can be used interchangeably.
  • port (optional) - The port to connect to. Defaults to 445.
  • username (optional) - The username of an account on the server. Defaults to guest
  • password (optional) - The password of the account. Defaults to empty
  • domain (optional) - The SMB NT domain. Defaults to WORKGROUP

Instead, an SMB connection url string may be used of the following format:

smb://[[<domain>;]<username>[:<password>]@]<host>[:<port>]/<share>[/path/to/folder][/]

This returns a promise resolving in an array of files. Each entry has the following properties:

  • filename - The name of the file
  • size - The entry's file size
  • sizeOnDisk - The file's allocation size on the remote drive
  • created - A js Date object with the time the file was created
  • accessed - A js Date object with the time the file was last accessed
  • modified - A js Date object with the time the contents of the file were last modified. This excludes attribute or meta information changes
  • changed - A js Date object with the time the file was last changed, including meta information and attributes
  • attributes - The combined attributes of the file. See the specification for all possible attributes.
  • directory - A boolean specifying whether this entry is a directory
  • hidden - A boolean specifying is this file is marked as hidden

Example

const smbEnumFiles = require('smb-enumerate-files') 

smbEnumFiles.enumerate({
  host: 'myserver',
  share: 'myshare',
  path: 'path/to/folder'
}).then(files => {
  // do something with these files
}).catch(err => console.log(err))

// or in an async function
const files = await smbEnumFiles.enumerate('smb://myserver/myshare/path/')

createSession(options)

Creates a session based on the given options. You would use this method rather than the above when you need to enumerate multiple paths because it does not close the session automatically after retrieval.

The options are the same as the above enumerate function. However, the path argument is ignored.

session.connect()

Connects this session. Must be called before other function can be used. Returns a promise that resolves when the client has successfully connected to the server

session.enumerate(path)

Retrieves the directory listing of the specified path. The path option must be a string with a relative path from the share. Leading and/or trailing slashes are allowed and slashes and backslashes can be interchangeably used. Returns a promise equal to the enumerate function above.

session.close()

Closes the session.

Example

const smbEnumFiles = require('smb-enumerate-files')

const paths = ['', '/path/to/folder/', 'otherpath']

const session = smbEnumfiles.createSession('smb://admin:hunter2@myserver/myshare')
await session.connect()
for(let path of paths) {
  const files = await session.enumerate(path)
  // do something with these files
}
session.close()

Bugs & Issues

This package is designed to be small and efficient, which means it does not have proper network package parsing. Problems may occur in non-typical situations. Please report issues in the issue tracker to improve this project.