Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Network Share/SMB Client

I'm trying to read a file from a android phone to a Windows share. I'm using now the StreamWriter, like below:

StreamWriter outfile = new StreamWriter(@"\\10.16.68.253\sam\AllTxtFiles.txt");
outfile.WriteLine("TESTGENREOIADNIWAN");

But i get a Access Denied. I already added the permission to the manifest. And i tested the share using the ES File Explorer (with everyone access). I used the same lines of code on a WPF app and works fine, so my problem is in Android app.

I already tried to change the connection string like the ES, smb://10.16.68.253/sam/AllTxtFiles.txt, but no luck.

Anyone accomplished this ?

Tks !

like image 715
Juliano Avatar asked Nov 05 '12 19:11

Juliano


People also ask

What is the SMB client?

What is an SMB client? An SMB client is the device that accesses resources on an SMB server. For example, within a corporate network, the user PCs that access a shared drive are SMB clients.

What is SMB client for Windows?

The Server Message Block (SMB) protocol is a network file sharing protocol that allows applications on a computer to read and write to files and to request services from server programs in a computer network. The SMB protocol can be used on top of its TCP/IP protocol or other network protocols.

What is the difference between NFS and SMB?

NFS has no fast file find; SMB has fast find. NFS no server and printer browsing, while SMB has server and printer browsing. NFS slower reads and writes; SMB faster. NFS better with small files, while SMB fine with small files but better with large files.


2 Answers

for me I had to set up the string like this "smb://username:password@local ip/" for the root of my server's Windows share.

like image 149
tantonj Avatar answered Oct 03 '22 22:10

tantonj


You have to make sure the connection to the SMB share is authenticated before trying to access any files. You have to use API calls to do this, because this stuff is done in the Win32 layer outside of managed code.

Here's a start:

http://www.pinvoke.net/default.aspx/mpr/WNetAddConnection.html

like image 20
Xavier J Avatar answered Oct 03 '22 22:10

Xavier J