You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Yogesh Kumar (JIRA)" <ji...@apache.org> on 2018/07/05 15:39:00 UTC

[jira] [Created] (VFS-665) Apache VFS FileObject copyFrom() Exception

Yogesh Kumar created VFS-665:
--------------------------------

             Summary: Apache VFS FileObject copyFrom() Exception
                 Key: VFS-665
                 URL: https://issues.apache.org/jira/browse/VFS-665
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 2.0
            Reporter: Yogesh Kumar


-1down vote [favorite|https://stackoverflow.com/questions/51194702/apache-vfs-fileobject-copyfrom-exception?noredirect=1]
 
I am using the below class to transfer a file from one folder to another on a server I am using commons-vfs-2.0 jar. :

{{import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemOptions; import org.apache.commons.vfs.Selectors; import org.apache.commons.vfs.impl.StandardFileSystemManager; import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder; public class SFTPTest { public static void main(String args[]) { try { String ftpUrlSrc = "sftp.host.address" + ":" + "8022" + "/SRC_FOLDER"; String sftpUriSrc = "sftp://" + "sftpUser" + ":" + "pass$123" + "@" + ftpUrlSrc; String ftpUrlDest = "sftp.host.address" + ":" + "8022" + "/DEST_FOLDER"; String sftpUriDest = "sftp://" + "sftpUser" + ":" + "pass$123" + "@" + ftpUrlDest; StandardFileSystemManager manager = new StandardFileSystemManager(); FileSystemOptions opts = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); manager.init(); FileObject fileObjectSrc = manager.resolveFile(sftpUriSrc + "/" + "trial_file.tar.gz", opts); FileObject fileObjectDest = manager.resolveFile(sftpUriDest + "/" + "trial_file.tar.gz", opts); fileObjectDest.copyFrom(fileObjectSrc, Selectors.SELECT_SELF); //The below moveTo() call works without any issue. fileObjectSrc.moveTo(fileObjectDest); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }}}

The below exception is being thrown:

{{ org.apache.commons.vfs.FileSystemException: Could not copy "sftp://sftpUser:***@sftp.host.address:8022/SRC_FOLDER/trial_file.tar.gz" to "sftp://sftpUser:***@sftp.host.address:8022/DEST_FOLDER/trial_file.tar.gz". at org.apache.commons.vfs.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:1032) at SFTPTest.main(SFTPTest.java:27) Caused by: org.apache.commons.vfs.FileSystemException: Could not close the output stream for file "sftp://sftpUser:***@sftp.host.address:8022/DEST_FOLDER/trial_file.tar.gz". at org.apache.commons.vfs.provider.DefaultFileContent$FileContentOutputStream.close(DefaultFileContent.java:686) at org.apache.commons.vfs.FileUtil.copyContent(FileUtil.java:119) at org.apache.commons.vfs.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:1023) ... 1 more Caused by: java.io.IOException: 4: Transfer failed possibly due to access restrictions. at com.jcraft.jsch.ChannelSftp$1.flush(ChannelSftp.java:858) at com.jcraft.jsch.ChannelSftp$1.close(ChannelSftp.java:867) at java.io.FilterOutputStream.close(FilterOutputStream.java:160) at org.apache.commons.vfs.util.MonitorOutputStream.close(MonitorOutputStream.java:56) at java.io.FilterOutputStream.close(FilterOutputStream.java:160) at org.apache.commons.vfs.util.MonitorOutputStream.close(MonitorOutputStream.java:56) at org.apache.commons.vfs.provider.DefaultFileContent$FileContentOutputStream.close(DefaultFileContent.java:682) ... 3 more}}{{}}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)