Saving jscape sftp permission file

I use jscape sftp to transfer files

 com.jscape.inet.sftp.Sftp Sftp sftpSession = null; // after the required step to connect // through SshParameters sftpSession.setDir(remotedirectory); sftpSession.upload(localFile, remoteFile); 

Now this code transfers the file, this part is OK. but the file resolution changes on the remote computer (it becomes 644).

 in local machine: -rw-rw-r-- 1 oracle dba 356 Jun 30 03:33 file1.test -rwxrw-rx 1 oracle dba 462 Jun 30 03:35 file2.test in remote machine: -rw-r--r-- 1 oracle dba 356 Jun 30 03:49 file1.test -rw-r--r-- 1 oracle dba 462 Jun 30 03:49 file2.test 

I see below a method to change the resolution of a deleted file,

com.jscape.inet.sftp.Sftp.setFilePermissions(java.lang.String remoteFile, int permissions)

My questions:

  • The com.jscape.inet.sftp.Sftp.upload method com.jscape.inet.sftp.Sftp.upload works this way, upload the file without saving permission?
  • is there any way to save permission without using setFilePermissions method explicitly?
+7
java upload ftp sftp
source share
2 answers

Does the user and groups on the remote computer have the same permissions as on the local one in the download directory? You can try to obtain permissions on local use of the getPermissions () method and set it for the remote file.

+4
source share

With Java 7+, you can do this; The code below, of course, assumes a configuration similar to yours that these are POSIX-compatible file systems at both ends.

The trick is to get a set of POSIX file permissions for the file; this is done with:

 // "fileToCopy" here is a Path; see Paths.get() Files.getPosixFilePermissions(fileToCopy) 

This will return a Set<PosixFilePermissions> , which is actually an enumeration. Converting an enumeration to an integer is done using the following trick:

 private static int toIntPermissions(final Set<PosixFilePermission> perms) { int ret = 0; for (final PosixFilePermission perm: PosixFilePermission.values()) { if (perms.contains(perm)) ret++; // add 1 ret <<= 1; // shift by 1 } return ret; } 

Regarding the direct saving of copy permissions, this is not possible in one command: SSH does not guarantee that the file system at the remote end supports them, but it recognizes the existence of such file systems, so it offers a dedicated command to set permissions at the remote end explicitly.

+1
source share

All Articles