nmtp 0.4.1
dotnet add package nmtp --version 0.4.1
NuGet\Install-Package nmtp -Version 0.4.1
<PackageReference Include="nmtp" Version="0.4.1" />
paket add nmtp --version 0.4.1
#r "nuget: nmtp, 0.4.1"
// Install nmtp as a Cake Addin #addin nuget:?package=nmtp&version=0.4.1 // Install nmtp as a Cake Tool #tool nuget:?package=nmtp&version=0.4.1
nmtp
nmtp is a fork of LibMtpSharp and a wrapper of libmtp with a few changes.
Use
To list available MTP devices, create a Nmtp.RawDeviceList
.
For an object-oriented API, create a Nmtp.Device
and use its instance methods.
If you need a low-level API, use Nmtp.Native.LibMtp
. The methods are mostly 1-1 with the C API. See the source or libmtp documentation for details.
Don't forget to dispose!
Platforms
The nuget packages includes native platform support for the following target frameworks:
win-x64
linux-x64
osx-x64
osx-arm64
Example
using var list = new Nmtp.RawDeviceList();
foreach(Nmtp.RawDevice device in list)
{
Console.WriteLine(device);
}
var rawDevice = list.First();
using var device = new Nmtp.Device()
bool isOpen = device.TryOpen(ref rawDevice, cached: true);
if (!isOpen) { return; }
IEnumerable<Nmtp.Folder> folders = device.GetFolderList(storage.Id);
var cameraDir = folders.FirstOrDefault(folder => folder.Name == "Camera"); // e.g. Android Camera directory
if (cameraDir.FolderId <= 0) { return; }
// Get all PNG files from the last 7 days
List<Nmtp.File> files = device
.GetFiles(progress =>
{
Log.Info($"List files progress: {progress * 100:##.#}%");
return true; // false: cancel, true: continue
})
.Where(file => file.ParentId == cameraDir.FolderId)
.Where(file => file.FileName.EndsWith(".png"))
.Where(file => DateTime.UnixEpoch + TimeSpan.FromSeconds(file.ModificationDate) > DateTime.UtcNow - TimeSpan.FromDays(7))
.ToList();
List<byte[]> data = files
.Select((Nmtp.File file) =>
{
using var ms = new MemoryStream();
bool ok = device.GetFile(file.ItemId, progress =>
{
Log.Info($"Download progress {file.FileName} {progress * 100:##.#}%");
return false; // false: continue, true: cancel
}, ms);
return ms.ToArray();
})
.ToList();
Logo
Logo icon generated by DALL-E 3.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.4.1 | 349 | 11/16/2023 |
Support Apple Silicon
Support all platforms from single nupkg