Skip to content

Instantly share code, notes, and snippets.

@quchie
Created April 3, 2014 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quchie/9951029 to your computer and use it in GitHub Desktop.
Save quchie/9951029 to your computer and use it in GitHub Desktop.
Grails write xml file to network folder in windows
import jcifs.smb.*
import groovy.xml.MarkupBuilder
import org.custommonkey.xmlunit.*
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.records() {
car(name:'HSV Maloo', make:'Holden', year:2006) {
country('Australia')
record(type:'speed', 'Production Pickup Truck with speed of 271kph')
}
car(name:'P50', make:'Peel', year:1962) {
country('Isle of Man')
record(type:'size', 'Smallest Street-Legal Car at 99cm wide and 59 kg in weight')
}
car(name:'Royale', make:'Bugatti', year:1931) {
country('France')
record(type:'price', 'Most Valuable Car at $15 million')
}
}
def ntlm = new NtlmPasswordAuthentication("", "username", "password"); //Authenticate without DOMAIN
SmbFile file = new SmbFile("smb://MYPC/Users/users/targetFolder"+"/quchfile.xml",ntlm);
SmbFileOutputStream newFile = new SmbFileOutputStream(file,true) // true = append each time write to this file
newFile.write(writer.toString().getBytes()) //start writing
newFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment