I create a XML and a ZIP file and upload them via SFTP to a server. The folder structure looks something like this:
/
|
|--/incoming
|
|--/<hash>
|
|-- file.xml
|-- file.zip
The folder <hash>
is created when I upload both XML and ZIP and I need this folder to have the permissions 777
.
As far as I can tell there is no way for me to change the permissions of an already created folder via VFS within Java. What I tried then was to create that folder locally, give it 777
and upload it with the XML and the ZIP inside.
My code looks like this:
File fUploadDir = new File(uploadDir);
fUploadDir.mkdir();
fUploadDir.setReadable(true, false);
fUploadDir.setWritable(true, false);
fUploadDir.setExecutable(true, false);
// Create and add ZIP and XML files...
// ...
StandardFileSystemManager manager = new StandardFileSystemManager();
// Initializes the file manager
manager.init();
File file = new File(pathToFolder);
// Setup our SFTP configuration
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
String sftpUri = "sftp://" + userId + ":" + password + "@" + serverAddress + "/" + remoteDirectory;
// Create local file object
FileObject localFile = manager.resolveFile(fUploadDir.getAbsolutePath());
// Create remote file object
FileObject remoteFile = manager.resolveFile(sftpUri, opts);
// Copy local file to sftp server
remoteFile.copyFrom(localFile, Selectors.SELECT_SELF_AND_CHILDREN);
When I execute this code the XML and the ZIP will be uploaded, but not the directory, so the structure on the SFTP server looks like this:
/
|
|--/incoming
|
|-- file.xml
|-- file.zip
How can I achieve to get the folder with permissions 777
up there?