[
https://issues.apache.org/jira/browse/VFS-617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16978387#comment-16978387
]
Gopal Warawate edited comment on VFS-617 at 11/20/19 12:48 PM:
---------------------------------------------------------------
Below simple code using moveTo Api from vfs2 use to work with
commons-vfs2-2.0.jar but it doesn’t work with version commons-vfs2-2.2.jar
it works perfectly fine with SFTP server running on LINUX, only it failse on
SFTP server running on windows server.
Please any suggestions.
ls command show as below on both server:
Windows :
sftp> ls -l
-rw-rw---- 1 no-user no-group 86 Nov 20 11:03 test.txt
Linux:
sftp> ls -l
-rwxr-xr-x 1 userttest dba 86 Nov 20 11:05 test.txt
Code sample:
public static boolean move(String hostName, String username, String password,
String remoteSrcFilePath, String remoteDestFilePath){
StandardFileSystemManager manager = new StandardFileSystemManager();
try {
manager.init();
// Create remote object
FileObject remoteFile = manager.resolveFile(createConnectionString(hostName,
username, password, remoteSrcFilePath), createDefaultOptions());
FileObject remoteDestFile =
manager.resolveFile(createConnectionString(hostName, username, password,
remoteDestFilePath), createDefaultOptions());
if (remoteFile.exists())
{ remoteFile.moveTo(remoteDestFile);; System.out.println("Move remote file
success"); return true; }
else
{ System.out.println("Source file doesn't exist"); return false; }
} catch (Exception e)
{ throw new RuntimeException(e); }
finally
{ manager.close(); }
}
Error:
[main] INFO org.apache.commons.vfs2.provider.sftp.SftpClientFactory -
Authentication succeeded (keyboard-interactive).
'id' is not recognized as an internal or external command,
operable program or batch file.
[main] INFO org.apache.commons.vfs2.provider.sftp.SftpClientFactory -
Disconnecting from XXXXX port 22
Exception in thread "main" java.lang.RuntimeException:
org.apache.commons.vfs2.FileSystemException: Could not determine if file
"sftp://!!!!!:***@XXXXX/C:/folder1" is writeable.
at com.test.SFTPUtility.move(SFTPUtility.java:107)
at com.test.SFTPUtility.main(SFTPUtility.java:35)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not determine if
file "sftp://!!!!!:***@XXXXX/C:/folder1" is writeable.
at
org.apache.commons.vfs2.provider.AbstractFileObject.isWriteable(AbstractFileObject.java:1602)
at
org.apache.commons.vfs2.provider.AbstractFileObject.moveTo(AbstractFileObject.java:1646)
at com.test.SFTPUtility.move(SFTPUtility.java:98)
... 1 more
Caused by: com.jcraft.jsch.JSchException: Could not get the groups id of the
current user (error code: 1)
at
org.apache.commons.vfs2.provider.sftp.SftpFileSystem.getGroupsIds(SftpFileSystem.java:237)
at
org.apache.commons.vfs2.provider.sftp.SftpFileObject.getPermissions(SftpFileObject.java:231)
at
org.apache.commons.vfs2.provider.sftp.SftpFileObject.doIsWriteable(SftpFileObject.java:263)
at
org.apache.commons.vfs2.provider.AbstractFileObject.isWriteable(AbstractFileObject.java:1594)
... 3 more
was (Author: gwarawate):
Below simple code using moveTo Api from vfs2 use to work with
commons-vfs2-2.0.jar but it doesn’t work with version commons-vfs2-2.2.jar
Please any suggestions.
public static boolean move(String hostName, String username, String password,
String remoteSrcFilePath, String remoteDestFilePath){
StandardFileSystemManager manager = new StandardFileSystemManager();
try {
manager.init();
// Create remote object
FileObject remoteFile = manager.resolveFile(createConnectionString(hostName,
username, password, remoteSrcFilePath), createDefaultOptions());
FileObject remoteDestFile =
manager.resolveFile(createConnectionString(hostName, username, password,
remoteDestFilePath), createDefaultOptions());
if (remoteFile.exists()) {
remoteFile.moveTo(remoteDestFile);;
System.out.println("Move remote file success");
return true;
}
else{
System.out.println("Source file doesn't exist");
return false;
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
manager.close();
}
}
Error:
[main] INFO org.apache.commons.vfs2.provider.sftp.SftpClientFactory -
Authentication succeeded (keyboard-interactive).
'id' is not recognized as an internal or external command,
operable program or batch file.
[main] INFO org.apache.commons.vfs2.provider.sftp.SftpClientFactory -
Disconnecting from XXXXX port 22
Exception in thread "main" java.lang.RuntimeException:
org.apache.commons.vfs2.FileSystemException: Could not determine if file
"sftp://!!!!!:***@XXXXX/C:/folder1" is writeable.
at com.test.SFTPUtility.move(SFTPUtility.java:107)
at com.test.SFTPUtility.main(SFTPUtility.java:35)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not determine if
file "sftp://!!!!!:***@XXXXX/C:/folder1" is writeable.
at
org.apache.commons.vfs2.provider.AbstractFileObject.isWriteable(AbstractFileObject.java:1602)
at
org.apache.commons.vfs2.provider.AbstractFileObject.moveTo(AbstractFileObject.java:1646)
at com.test.SFTPUtility.move(SFTPUtility.java:98)
... 1 more
Caused by: com.jcraft.jsch.JSchException: Could not get the groups id of the
current user (error code: 1)
at
org.apache.commons.vfs2.provider.sftp.SftpFileSystem.getGroupsIds(SftpFileSystem.java:237)
at
org.apache.commons.vfs2.provider.sftp.SftpFileObject.getPermissions(SftpFileObject.java:231)
at
org.apache.commons.vfs2.provider.sftp.SftpFileObject.doIsWriteable(SftpFileObject.java:263)
at
org.apache.commons.vfs2.provider.AbstractFileObject.isWriteable(AbstractFileObject.java:1594)
... 3 more
> isReadable fails if unable to determine group identity
> ------------------------------------------------------
>
> Key: VFS-617
> URL: https://issues.apache.org/jira/browse/VFS-617
> Project: Commons VFS
> Issue Type: Bug
> Affects Versions: 2.1
> Environment: Windows 7 Java 7. Failure occured connecting via SFTP to
> a Synology box running DSM 6.
> Reporter: Tim Nickels
> Priority: Major
>
> The doIsReadable method of SftpFileObject throws an exception if the system
> cannot identify group/owner permissions.......
> Exception in thread "main" org.apache.commons.vfs2.FileSystemException: Could
> not determine if file "sftp://myURI" is readable.
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.isReadable(AbstractFileObject.java:1761)
> at com.avenca.vfs.VFSUtils.main(VFSUtils.java:41)
> Caused by: com.jcraft.jsch.JSchException: Could not get the groups id of the
> current user (error code: 1)
> at
> org.apache.commons.vfs2.provider.sftp.SftpFileSystem.getGroupsIds(SftpFileSystem.java:263)
> at
> org.apache.commons.vfs2.provider.sftp.SftpFileObject.getPermissions(SftpFileObject.java:317)
> at
> org.apache.commons.vfs2.provider.sftp.SftpFileObject.doIsReadable(SftpFileObject.java:335)
> at
> org.apache.commons.vfs2.provider.AbstractFileObject.isReadable(AbstractFileObject.java:1757)
> The problem is the method is using
> return getPermissions(true).isReadable()
> The folder *is* readable without these permissions, and so should be set to
> return getPermissions(false).isReadable()
> Which correctly allows the system to identify a readable folder without
> adding unnecessary restrictions.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)