forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmbget.java
More file actions
executable file
·39 lines (36 loc) · 1.2 KB
/
Copy pathsmbget.java
File metadata and controls
executable file
·39 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package javaforce.utils;
/**
* Created : May 10, 2012
*
* @author pquiring
*/
import javaforce.*;
public class smbget {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage:jsmbget smb://server/share/file [--user=user] [--pass=pass]");
System.out.println("Note:DOMAINNAME and PASSWORD environment variables are used by default");
System.exit(0);
}
String user = System.getenv("DOMAINNAME"); //username on domain
String pass = System.getenv("PASSWORD");
for (int a = 1; a < args.length; a++) {
if (args[a].startsWith("--user=")) {
user = args[a].substring(7);
}
if (args[a].startsWith("--pass=")) {
pass = args[a].substring(7);
}
}
if ((user == null) || (pass == null)) {
user = "";
pass = "";
}
ShellProcess sp = new ShellProcess();
sp.addRegexResponse("Username.+", user + "\n", false);
sp.addRegexResponse("Password.+", pass + "\n", false);
//NOTE : smbget buffers output strangely preventing ShellProcess from getting it, but openpty fixes that
sp.run(new String[]{"openpty", "/usr/bin/smbget", args[0]}, false);
System.exit(sp.getErrorLevel());
}
}