jscape sftp上传保留文件权限

Den*_*tta 7 java ftp upload sftp

jscape sftp用来传输文件

com.jscape.inet.sftp.Sftp

Sftp sftpSession = null;

// after the required step to connect
// through SshParameters

sftpSession.setDir(remotedirectory);
sftpSession.upload(localFile, remoteFile);
Run Code Online (Sandbox Code Playgroud)

现在,这段代码正在传输文件,那部分OK.但是文件权限在远程机器中被更改(它变为644).

in local machine:    
-rw-rw-r-- 1 oracle dba  356 Jun 30 03:33 file1.test
-rwxrw-r-x 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
Run Code Online (Sandbox Code Playgroud)

我看到以下方法来更改远程文件的权限,

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

我的问题是,

  • 做的com.jscape.inet.sftp.Sftp.upload方法只能这样,上传的文件不保留的权限?
  • 有没有办法保留权限,而不setFilePermissions明确使用方法?

Gau*_*ose 5

远程用户和组对于上传的目录是否具有与本地相同的权限?您可以尝试使用 getPermissions() 方法获取本地权限并将其设置为远程文件。