Introduction JCIFS是java-based存取網路芳鄰通訊協定的API。 之所以接觸這個API,是因為好奇Windows管理工具psexec,能將Local程式放到Remote並執行的做法。後來看到類似工具 paexec 程式碼,與經過自己的測試,發現原理是將程式複製到遠端的 管理共享資料夾 ,再透過WMI呼叫外部程式。 接下來將說明我有使用的API。 How to? 首先至 link 下載library。接下來就是寫寫寫。 Create File 大部分的操作都可以透過SmbFile類別完成。而與遠端的機器認證,是透過NTLM通訊協定。 private static NtlmPasswordAuthentication createAuth ( String aUser, String aPasswd ) { StringBuffer sb = new StringBuffer ( aUser ) ; sb. append ( ':' ) . append ( aPasswd ) ; return new NtlmPasswordAuthentication ( sb. toString ( ) ) ; } public static SmbFile createSmbFile ( String aUser, String aPasswd, String aTarget ) throws IOException { NtlmPasswordAuthentication auth = createAuth ( aUser, aPasswd ) ; return new SmbFile ( aTarget, auth ) ; } 如果有網域,可以使用 new NtlmPasswordAuthentication ( domain, user, passwd ) ; 在建立完SmbFile物件後,剩下其實就和操作一般檔案無異。 public static void createFile ( String aUser, String aPasswd, String aTarget, String aContent ) ...