[jcifs] want to connect to a standalone window laptop and write file
SunnyChan2012
sunnychan2012 at yahoo.com
Fri Nov 7 07:57:52 MST 2014
Hi,
I want to compile an android app to write file to a window laptop, which is
a workgroup (default in windows WORKGROUP) with username and password. I
find some codes on the web but still cannot run it successfully with
eclipse.
I get exception at the code:
FileOutputStream mFileOutputStream = new FileOutputStream(
mLocalFile);
Also, I also find that the code :
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(
null, yourPeerName, yourPeerPassword);
do not really make any connection test with the workgroup as I can run it
without exception throw using false username and passwords! Why?
public void connectingWithSmbServer() {
try {
String yourPeerPassword = "administrator";
String yourPeerName = "abcd1234";
String yourPeerIP = "192.168.1.3";
String path = "smb://" + yourPeerIP;
String path2 = "smb://" + yourPeerIP + "/myShare/logo.jpg";
NtlmPasswordAuthentication auth = new
NtlmPasswordAuthentication(
null, yourPeerName, yourPeerPassword);
Log.e("Connected", "Yes"); // ! I have no error here with
false username and passwords!
SmbFile smbFile = new SmbFile(path, auth);
SmbFile smbFile2 = new SmbFile(path2, auth);
/** Printing Information about SMB file which belong to your
Peer **/
String nameoffile = smbFile.getName();
String pathoffile = smbFile.getPath();
Log.e(nameoffile, pathoffile);
File root = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"_Today");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, "logo" + ".png");
downloadFileFromPeerToSdcard(gpxfile, smbFile2);
Log.e(nameoffile, pathoffile);
} catch (Exception e) {
e.printStackTrace();
Log.e("Connected", e.getMessage());
}
}
public void downloadFileFromPeerToSdcard(File mLocalFile, SmbFile mFile) {
try {
SmbFileInputStream mFStream = new SmbFileInputStream(mFile);
mLocalFile = new
File(Environment.getExternalStorageDirectory(),
mFile.getName());
FileOutputStream mFileOutputStream = new FileOutputStream(
mLocalFile);
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = mFStream.read(buffer)) > 0) {
mFileOutputStream.write(buffer, 0, len1);
}
mFileOutputStream.close();
mFStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("MalformURL", e.getMessage());
} catch (SmbException e) {
e.printStackTrace();
Log.e("SMBException", e.getMessage());
} catch (Exception e) {
e.printStackTrace();
Log.e("Exception", e.getMessage());
}
}
--
View this message in context: http://samba.2283325.n4.nabble.com/want-to-connect-to-a-standalone-window-laptop-and-write-file-tp4675732.html
Sent from the Samba - jcifs mailing list archive at Nabble.com.
More information about the jCIFS
mailing list