Closed playerjamesbattleground closed 9 years ago
to be more specific, it should be mkdirs
in case folders from parent path also need to be created.
I found maybe here is where the line should be added? https://github.com/dirk-olmes/mule-transport-cifs/blob/master/src/main/java/org/mule/transport/cifs/SmbConnector.java#L171
here is the snippet that I've done as a walkaround:
//SMBConnector.java
...
SmbFile smbFile;
SmbFile smbDir;
try
{
String filename = getFilename(endpoint, event);
EndpointURI uri = endpoint.getEndpointURI();
if (checkNullOrBlank(uri.getUser()) || checkNullOrBlank(uri.getPassword()))
{
logger.warn("No user or password supplied. Attempting to connect with just smb://<host>/<path>");
logger.info("smb://" + uri.getHost() + uri.getPath() + "/" + filename);
smbFile = new SmbFile("smb://" + uri.getHost() + uri.getPath() + filename);
smbDir = new SmbFile("smb://" + uri.getHost() + uri.getPath());
}
else
{
logger.info("smb://" + uri.getUser() + ":<password hidden>@" + uri.getHost() + uri.getPath() + filename);
String url = "smb://" + uri.getUser() + ":" + uri.getPassword() + "@" + uri.getHost() + uri.getPath() + filename;
smbFile = new SmbFile(url);
smbDir = new SmbFile("smb://" + uri.getUser() + ":" + uri.getPassword() + "@" + uri.getHost() + uri.getPath());
}
if (!smbDir.exists()) {
logger.info("making path to file: "+smbDir.getPath()+" isDirectory "+smbDir.isDirectory());
smbDir.mkdirs();
}
if (!smbFile.exists())
{
smbFile.createNewFile();
}
...
Thanks Dirk, very quick response and I agree the createIntermediateDir should be an optional choice to most of users
Hi Dirk,
One of our use case is when sending files to network share via smb, if the path/to/file doesn't exists, it should create directories in flight.
Eg. sending to smb://host/a/b/c/d/xyz.json, but in the remote drive there is only /a/b, then c/d should be created dynamically.
I found this http://stackoverflow.com/questions/24527045/how-to-create-directories-using-samba-client from the answer it seems just add checks whenever doing
new SmbFile()
and callmkdir
if path to file is n/a, is it possible you could update this?Thanks very much
James