public static void uploadFile(Path source, String path, String filename) throws SmbException, UnknownHostException, IOException { String user = null; NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(user); SmbFile sFile = new SmbFile(path, auth); sFile.mkdirs(); sFile = new SmbFile(path + filename, auth); SmbFileOutputStream sfos = new SmbFileOutputStream(sFile); sfos.write(Files.readAllBytes(source)); }
public static void main(String argv[]) throws Exception { SmbFileOutputStream out; SmbFile f = new SmbFile(argv[0], "", null, SmbFile.FILE_NO_SHARE); out = new SmbFileOutputStream(f); System.in.read(); out.close(); System.in.read(); // OR out = new SmbFileOutputStream(argv[1], SmbFile.FILE_NO_SHARE); System.in.read(); out.close(); System.in.read(); }
/* fetch files from the server and store in bufferedReaders array which is a global variable */ public boolean FetchFiles(String fileName, int pos) { BufferedReader br; try { GlobalCache.Prefs = getSharedPreferences("label", 0); // set credentials so that the app can login into the server jcifs.Config.setProperty( "jcifs.netbios.wins", GlobalCache.Prefs.getString("IPAddress", GlobalCache.IPAddress)); jcifs.Config.setProperty( "jcifs.smb.client.domain", GlobalCache.Prefs.getString("Domain", GlobalCache.Domain)); jcifs.Config.setProperty( "jcifs.smb.client.username", GlobalCache.Prefs.getString("Username", GlobalCache.Username)); jcifs.Config.setProperty( "jcifs.smb.client.password", GlobalCache.Prefs.getString("Password", GlobalCache.Password)); String ILocation = GlobalCache.Prefs.getString("Import", GlobalCache.DownLoadLocation); SmbFile smbFile = new SmbFile( ILocation + "Round " + GlobalCache.savedRoundNum + "/" + fileName); // !!!!!!!!!!!!!!! // smb://192.168.12.6/Database/Admin/Devin/test.txt // !!!!!!!!!!!!!!!!!! br = new BufferedReader(new InputStreamReader(new SmbFileInputStream(smbFile))); // Upload a confirmation file SmbFile f = new SmbFile( ILocation + "Round " + GlobalCache.savedRoundNum + "/" + "DownloadConfirmation.txt"); SmbFileOutputStream out = new SmbFileOutputStream(f, true); byte[] msg; Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); String DownloadedDate = df.format(c.getTime()); msg = (fileName + " - " + DownloadedDate + "\r\n").getBytes("US-ASCII"); out.write(msg); out.close(); } catch (UnknownHostException e1) { return false; } catch (SmbException e1) { return false; } catch (MalformedURLException e1) { return false; } catch (IOException e1) { return false; } bufferedReaders[pos] = br; return true; }