使用 Mono on LAN 上传到 Android 设备上的 Windows 网络共享
Uploading to a Windows network share on Android device using Mono on LAN
我已经阅读了一些关于此的帖子,但我有一个问题没有得到明确回答,所以我发布了这个。
我正在使用 Mono 创建一个 C# Android 应用程序,它可以选择将文件备份到多个在线共享、OneDrive、Google 云、FTP 和本地网络共享。
除上传到本地网络共享外,其他所有方法都已排序。
这个想法是,当人们处于高速本地无线网络中时,他们将使用它,这将非常快速地将数据直接复制到服务器上的共享上。 \SERVER\share
问题是,您无法将凭据传递给 File.Copy()
那么最好的下降方式是什么?
1.) 据说您可以从 MPR.dll P\Invoke WNetAddConnection2。这在 Windows 上效果很好,但在 Android 上会出现 DllNotFound。是否可以将此库复制到 phone 和 P\Invoke 以实现这一功能?
How to provide user name and password when connecting to a network share
2.) 可以使用 WindowsIdentity 来使用 Impersonation,同样,它在 windows 机器上运行良好,但它在 Android [=47= 上运行吗? ]?
3.) 据我所知,可以使用 SMB 协议 scan\access 本地网络,我一直在查看 CIFSClient 库,但目前它似乎对我不起作用。
4.) 是否有可以从 Mono 调用的 Java 方法,它可以简单地通过网络进行复制?
欢迎任何帮助,
c
编辑:现在全部排序。 JCIFS 绑定库成功了。
1.) Is it possible to copy this (MPR.dll) library to the phone and P\Invoke it for this one function?
否(这是本机 Win32 库)
2.) It is possible to use Impersonation using WindowsIdentity, again, works great on a windows machine, but does it work on an Android phone?
没有
3.) It's possible to scan\access a local network using SMB protocol as I understand, I've been looking at the CIFSClient library, but it's not seeming to work for me at the minute.
是(关于 SMB)
? (关于 CIFSClient,从未使用过)
4.) Is there a Java method that can be called from Mono that can simply do a copy over a network?
否(关于 SMB 份额)
Android 和 SMB:
我使用了 jCIFS,它是一个纯 Java 库,在 Xamarin Android 项目上实现了 SMB 协议。
免责声明:这是一个 jCIFS Java 到我的 public 存储库中的 C# 绑定库:
Jcifs.Smb.SmbFileInputStream的用法示例:
// This is NOT best-practice code, just showing a demo of an Jcifs api call
public async Task getFileContents ()
{
await Task.Run (() => {
var smbStream = new SmbFileInputStream ("smb://guest@10.10.10.5/code/test.txt");
byte[] b = new byte[8192];
int n;
while ((n = smbStream.Read (b)) > 0) {
Console.Write (Encoding.UTF8.GetString (b).ToCharArray (), 0, n);
}
Button button = FindViewById<Button> (Resource.Id.myButton);
RunOnUiThread(() => {
button.Text = Encoding.UTF8.GetString (b);
});
}
).ContinueWith ((Task arg) => {
Console.WriteLine (arg.Status);
if (arg.Status == TaskStatus.Faulted)
Console.WriteLine (arg.Exception);
}
);
}
我已经阅读了一些关于此的帖子,但我有一个问题没有得到明确回答,所以我发布了这个。
我正在使用 Mono 创建一个 C# Android 应用程序,它可以选择将文件备份到多个在线共享、OneDrive、Google 云、FTP 和本地网络共享。
除上传到本地网络共享外,其他所有方法都已排序。 这个想法是,当人们处于高速本地无线网络中时,他们将使用它,这将非常快速地将数据直接复制到服务器上的共享上。 \SERVER\share
问题是,您无法将凭据传递给 File.Copy() 那么最好的下降方式是什么?
1.) 据说您可以从 MPR.dll P\Invoke WNetAddConnection2。这在 Windows 上效果很好,但在 Android 上会出现 DllNotFound。是否可以将此库复制到 phone 和 P\Invoke 以实现这一功能? How to provide user name and password when connecting to a network share
2.) 可以使用 WindowsIdentity 来使用 Impersonation,同样,它在 windows 机器上运行良好,但它在 Android [=47= 上运行吗? ]?
3.) 据我所知,可以使用 SMB 协议 scan\access 本地网络,我一直在查看 CIFSClient 库,但目前它似乎对我不起作用。
4.) 是否有可以从 Mono 调用的 Java 方法,它可以简单地通过网络进行复制?
欢迎任何帮助, c
编辑:现在全部排序。 JCIFS 绑定库成功了。
1.) Is it possible to copy this (MPR.dll) library to the phone and P\Invoke it for this one function?
否(这是本机 Win32 库)
2.) It is possible to use Impersonation using WindowsIdentity, again, works great on a windows machine, but does it work on an Android phone?
没有
3.) It's possible to scan\access a local network using SMB protocol as I understand, I've been looking at the CIFSClient library, but it's not seeming to work for me at the minute.
是(关于 SMB)
? (关于 CIFSClient,从未使用过)
4.) Is there a Java method that can be called from Mono that can simply do a copy over a network?
否(关于 SMB 份额)
Android 和 SMB:
我使用了 jCIFS,它是一个纯 Java 库,在 Xamarin Android 项目上实现了 SMB 协议。
免责声明:这是一个 jCIFS Java 到我的 public 存储库中的 C# 绑定库:
Jcifs.Smb.SmbFileInputStream的用法示例:
// This is NOT best-practice code, just showing a demo of an Jcifs api call
public async Task getFileContents ()
{
await Task.Run (() => {
var smbStream = new SmbFileInputStream ("smb://guest@10.10.10.5/code/test.txt");
byte[] b = new byte[8192];
int n;
while ((n = smbStream.Read (b)) > 0) {
Console.Write (Encoding.UTF8.GetString (b).ToCharArray (), 0, n);
}
Button button = FindViewById<Button> (Resource.Id.myButton);
RunOnUiThread(() => {
button.Text = Encoding.UTF8.GetString (b);
});
}
).ContinueWith ((Task arg) => {
Console.WriteLine (arg.Status);
if (arg.Status == TaskStatus.Faulted)
Console.WriteLine (arg.Exception);
}
);
}