To copy a file, I use this construction:
SmbFiles.copy(local_file_path, share, path_for_server, true);
But it only copies the file to the server without assigning attributes of the local file such as the date of creation, change. As I understand it, the copy method does not have similar capabilities.
To do this, I have another code that can assign attributes to a file on the server, but only from another remote file on the same server:
try (DiskShare share = (DiskShare) session.connectShare(shareName)) {
String original = path + "2.txt"; // file name on the server
String dest = path + "4.txt"; // file name on the server
FileBasicInformation current = share.getFileInformation(original, FileBasicInformation.class);
long newAttrs = current.getFileAttributes() ^ FileAttributes.FILE_ATTRIBUTE_READONLY.getValue();
FileBasicInformation update = new FileBasicInformation(
current.getCreationTime(),
current.getLastAccessTime(),
current.getLastWriteTime(),
current.getChangeTime(),
newAttrs
);
DiskEntry e = share.open(dest, EnumSet.of(AccessMask.FILE_WRITE_ATTRIBUTES), (Set) null,
SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OPEN, (Set) null);
e.setFileInformation(update);
} catch (
IOException e) {
e.printStackTrace();
}
Please tell me how can I take data from a local file and assign it to a file on the server?
To copy a file, I use this construction:
SmbFiles.copy(local_file_path, share, path_for_server, true);
But it only copies the file to the server without assigning attributes of the local file such as the date of creation, change. As I understand it, the copy method does not have similar capabilities.To do this, I have another code that can assign attributes to a file on the server, but only from another remote file on the same server:
Please tell me how can I take data from a local file and assign it to a file on the server?