Repository navigation
Pulling folder content #98
Copy link
Copy link
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
Activity
It takes my afternoon...
await PullFolderAsync("/sdcard/Documents/SAI", "C:/Users/qq251/Downloads/Compressed/Test"); async Task PullFolderAsync(string remotePath, string localPath) { if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } using SyncService service = new(device); FileStatistics stat = await service.StatAsync(remotePath); await PullFolderAsyncInternal(stat, remotePath, localPath); async Task PullFolderAsyncInternal(FileStatistics stat, string remotePath, string localPath) { if (stat.FileType.HasFlag(UnixFileType.Directory)) { if (remotePath != stat.Path) { localPath = Path.Combine(localPath, stat.Path); remotePath = LinuxPath.Combine(remotePath, stat.Path); } if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } foreach (FileStatistics item in await service.GetDirectoryListingAsync(remotePath)) { await PullFolderAsyncInternal(item, remotePath, localPath); } } else if (stat.FileType.HasFlag(UnixFileType.Regular)) { string localFilePath = Path.Combine(localPath, stat.Path); await using FileStream stream = File.OpenWrite(localFilePath); await service.PullAsync(LinuxPath.Combine(remotePath, stat.Path), stream); await stream.FlushAsync(); } } }
@wherewhere Thank you so much sir!
But using your code leads to the famousThe server returned an invalid sync response 0. error.
I'm using the lastest release,v3.1.10(wpf app)Because I fixed it in new commit.
You need to reopen the service after pull, push and list.It will be like in next version
using SyncService service = new(device); await PullFolderAsync("/sdcard/Documents/SAI", "C:/Users/qq251/Downloads/Compressed/Test"); async Task PullFolderAsync(string remotePath, string localPath) { if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } using SyncService service = new(device); FileStatistics stat = await service.StatAsync(remotePath); await PullFolderAsyncInternal(stat, remotePath, localPath); async Task PullFolderAsyncInternal(FileStatistics stat, string remotePath, string localPath) { switch (stat.FileMode.GetFileType()) { case UnixFileStatus.Directory: if (remotePath != stat.Path) { localPath = Path.Combine(localPath, stat.Path); remotePath = LinuxPath.Combine(remotePath, stat.Path); } if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } foreach (FileStatistics item in await service.GetDirectoryListingAsync(remotePath)) { await PullFolderAsyncInternal(item, remotePath, localPath); } break; case UnixFileStatus.Regular: string localFilePath = Path.Combine(localPath, stat.Path); await using (FileStream stream = File.OpenWrite(localFilePath)) { await service.PullAsync(LinuxPath.Combine(remotePath, stat.Path), stream); await stream.FlushAsync(); } break; } } }
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed
What can we do for you?
this is my code to pull the dcim image on the android main storage:
I'm getting this error:
Failed to pull '/sdcard/dcim/Camera'. read failed: Is a directoryI can't specify in advance the full path,
"/sdcard/dcim/camera"because my program need to pull the entire "dcim" content,and it might be dynamic content,and contain many other folders inside....is there any way to pull is like using the simple shell command "adb pull /sdcard/dcim"(which would do the work perfectly)?Thanks in advance guys!