
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
luck-node-mtp
Advanced tools
cross-platform android device file management tool, based on libmtp. Support `MacOs`, `Windows`, `linux` platforms.
nodejs cross-platform android device file management tool, based on libmtp. Support MacOs, Windows, linux platforms.
English | 简体中文
install
npm i luck-node-mtp
simple use dmeo:
const mtp = require("luck-node-mtp");
// connect first device be found
mtp.connect();
// download from device to local
mtp.download("data/com.ahyungui.android/db/upload.zip","/Users/tmp/upload.zip",(send,total)=>{
console.log("progress",send,total);
});
// release device
mtp.release();
const mtp = require("luck-node-mtp");
// connect first device be found
mtp.connect();
try{
// download from device to local
mtp.download("data/com.ahyungui.android/db/upload.zip","/Users/tmp/upload.zip",(send,total)=>{
console.log("progress",send,total);
});
}
catch(e)
{
console.error(e);
}
finally{
// release device
mtp.release();
}
This ensures that the device can be released.
bool connect(uint vid?, uint pid?)
Connect device
If parameters vendor id and product id not set,the first device found will be connected
true if the operate was successfulresult = mtp.connect();
To access a certain device through vendor id and product id, you can get device information through getDeviceInfo method.
result = mtp.connect(vid,pid);
bool release()
Release the currently connected device.
The device needs to be released after use, otherwise an error will be reported when connecting again.
true if the operate was successfulresult = mtp.release();
array getList(string parentPath)
Get object list by a mtp device parent path.
A file tree can be build by this method.
/.result = mtp.getList("/data/com.ahyungui.android/db/");
console.log("objArr:",result);
Examples of output results are as follows:
[
{
name: '1',
size: 0,
type: 'FOLDER',
id: 156,
modificationdate: 1672041505,
parent_id: 152,
storage_id: 65537
},
{
name: 'download.zip',
size: 8893742,
type: 'FILE',
id: 158,
modificationdate: 1673321627,
parent_id: 152,
storage_id: 65537
}
]
array getDeviceInfo()
If multiple devices are connected, the device list can be obtained through this method.
result = mtp.getDeviceInfo();
console.log("deviceArr:",result);
Examples of output results are as follows:
[
{
vendor: 'MediaTek Inc',
vendor_id: 3725,
product: 'Elephone P8000',
product_id: 8221
}
]
bool upload(string localFilePath, string targetFolderPath, string progressCallBackFun?)
Upload local files to the device.
true if the operate was successfulresult = mtp.upload("/Users/tmp/download.zip", "data/com.ahyungui.android/db", (send, total) => {
console.log("progress", send, total);
});
bool del(string targetPath)
This function deletes a single file, track, playlist, folder or any other object off the MTP device, identified by the object ID.
If you delete a folder, there is no guarantee that the device will really delete all the files that were in that folder, rather it is expected that they will not be deleted, and will turn up in object listings with parent set to a non-existant object ID. The safe way to do this is to recursively delete all files (and folders) contained in the folder, then the folder itself.
true if the operate was successfulresult = mtp.del("/data/com.ahyungui.android/db/download.zip");
object getObject(string targetPath)
Obtain object information in the device, including files, folders, etc.
result = mtp.get("data/com.ahyungui.android/db/upload.zip");
Examples of output results are as follows:
{
name: 'upload.zip',
size: 8893742,
type: 'FILE',
id: 163,
modificationdate: 1673149510,
parent_id: 152,
storage_id: 65537
}
bool copy(string sourcePath, string targetFolderPath)
The semantics of copying a folder are not defined in the spec, but it appears to do the right thing when tested (but devices that implement this operation are rare).
Note that copying an object may take a significant amount of time.
MTP does not provide any kind of progress mechanism, so the operation will simply block for the duration.
true if the operate was successfulresult = mtp.copy("/data/com.ahyungui.android/db/download.zip","/data/com.ahyungui.android/db/8057");
bool move(string sourcePath, string targetFolderPath)
The function moves an object from one location on a device to another location.
The semantics of moving a folder are not defined in the spec, but it appears to do the right thing when tested (but devices that implement this operation are rare).
Note that moving an object may take a significant amount of time, particularly if being moved between storages. MTP does not provide any kind of progress mechanism, so the operation will simply block for the duration.
true if the operate was successfulresult = mtp.move("/data/com.ahyungui.android/db/download.zip","/data/com.ahyungui.android/db/8057");
bool setFileName(string targetPath, string newName)
Set the file name in device.
true if the operate was successfulresult = mtp.setFileName("/data/com.ahyungui.android/db/download.zip", "download1.zip");
bool setFolderName(string targetPath, string newName)
Set the folder name.
true if the operate was successfulresult = mtp.setFolderName("/data/com.ahyungui.android/db/8057", "8067");
uint createFolder(string parentFolderPath, string newName)
Create a folder on the current MTP device.
result = mtp.createFolder("/data/com.ahyungui.android/db", "test_folder");
array getCurrentDeviceStorageInfo()
Get the storage information of the currently connected device.
result = mtp.getCurrentDeviceStorageInfo();
Examples of output results are as follows:
[
{
id: 65537,
StorageDescription: '内部共享存储空间',
VolumeIdentifier: ''
}
]
bool setStorage(uint storageId)
Set the default device store for the currently connected device.
If there are multiple storages in the device, you can first obtain the device storage list through getCurrentDeviceStorageInfo,
After setting the default storage, all file management operations will be based on this storage by default.
If the default storage is not set, the device will select the first storage as the default storage when connecting.
true if the operate was successfulmtp.connect();
result = mtp.getCurrentDeviceStorageInfo();
console.log("objArr:",result);
result = mtp.setStorage(result[0].id);
mtp.release();
The current version has prebuild the binary files of darwin-x64 and win32-x64, which means that users of these two OS can use them directly without recompiling.
Users of other OS need to build their own development environment to recompile. For details, please refer to the Development Environment chapter.
At the same time, I also look forward to your friends to PR the prebuild files of other systems that you have precompiled into this project.
Note: The Windows platform needs to install the
WinUSB,libusb-win32orlibusbKdriver to work properly, it is recommended to useZadigto Manage the drivers of each device. The way to manage the drivers throughZadigis as follows:
Connect your mobile device to the system
List all USB devices via Zadig menu
Then select the MTP device to replace the driver- 然后选择MTP设备更换驱动
As shown in the picture:

Note: In addition, when the mobile phone is connected to the system, you need to select the
file transfer (MTP)mode to use it.
There is an example under the Mac platform in install/after.js, you can do some follow-up work after the precompiled file is generated, such as:
if (os.platform() == "darwin") {
// init share obj
shell.exec('cp -rf /usr/local/opt/libmtp/lib/libmtp.9.dylib ' + _rootPath + '/prebuilds/darwin-x64/libmtp.dylib');
shell.exec('cp -rf /usr/local/opt/libusb/lib/libusb-1.0.0.dylib ' + _rootPath + '/prebuilds/darwin-x64/libusb.dylib');
shell.exec('install_name_tool -change /usr/local/opt/libmtp/lib/libmtp.9.dylib @loader_path/libmtp.dylib ' + _rootPath + '/prebuilds/darwin-x64/node.napi.node');
shell.exec('install_name_tool -change /usr/local/opt/libusb/lib/libusb-1.0.0.dylib @loader_path/libusb.dylib ' + _rootPath + '/prebuilds/darwin-x64/libmtp.dylib');
console.log('node.napi.node links:',shell.exec('otool -L '+_rootPath+'/prebuilds/darwin-x64/node.napi.node'));
console.log('libmtp.dylib links:',shell.exec('otool -L '+_rootPath+'/prebuilds/darwin-x64/libmtp.dylib'));
}
Need to install xcode, nodejs 14+ development environment.
In addition, you need to install the libmtp library:
brew install libmtp
Need to install Visual Studio, nodejs 14+, python3 development environment.
Need to install libmtp-dev:
sudo apt-get install libmtp-dev
You can run the following command to test the files under the test file:
// test test/test_connect.js
npm run test connect
FAQs
cross-platform android device file management tool, based on libmtp. Support `MacOs`, `Windows`, `linux` platforms.
The npm package luck-node-mtp receives a total of 4 weekly downloads. As such, luck-node-mtp popularity was classified as not popular.
We found that luck-node-mtp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.