zhwq1216 opened a new pull request #215:
URL: https://github.com/apache/commons-vfs/pull/215


   Try to copy a file from local to sftp server, if the sftp target directory 
can't write by the sftp user, it throw a exception as below.
   
   ```
   Caused by: org.apache.commons.vfs2.FileSystemException: Could not write to 
"sftp://sftpuser:***@localhost/noperms/test.dat.tmp";.
        at 
org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1270)
        at 
org.apache.commons.vfs2.provider.DefaultFileContent.buildOutputStream(DefaultFileContent.java:540)
        at 
org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:406)
        at 
org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:394)
        at 
org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:815)
        at 
org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:833)
        at org.apache.commons.vfs2.FileUtil.copyContent(FileUtil.java:37)
        at 
org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:297)
        ... 29 common frames omitted
   Caused by: com.jcraft.jsch.SftpException: Permission denied
        at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
        at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:768)
        at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:709)
        at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:706)
        at 
org.apache.commons.vfs2.provider.sftp.SftpFileObject.doGetOutputStream(SftpFileObject.java:483)
        at 
org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1266)
        ... 36 common frames omitted
   ```
   the exception is from the version 2.5.0.
   
   the retry times is more than 20, then the exception stack as below:
   ```
   Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to 
SFTP server at "sftp://sftpuser:***@localhost/";.
        at 
org.apache.commons.vfs2.provider.sftp.SftpFileSystem.getChannel(SftpFileSystem.java:159)
        at 
org.apache.commons.vfs2.provider.sftp.SftpFileObject.statSelf(SftpFileObject.java:106)
        at 
org.apache.commons.vfs2.provider.sftp.SftpFileObject.doGetType(SftpFileObject.java:76)
        at 
org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1368)
        ... 30 common frames omitted
   Caused by: com.jcraft.jsch.JSchException: channel is not opened.
        at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:768)
        at com.jcraft.jsch.Channel.connect(Channel.java:151)
        at 
org.apache.commons.vfs2.provider.sftp.SftpFileSystem.getChannel(SftpFileSystem.java:133)
        ... 33 common frames omitted
   ```
   
   Although the sftp directory permission problem is fixed, the file cannot be 
copied to the sftp target directory, and the error stack still `channel is not 
opened`.
   
   The PR  try to catch  the exception on `SftpFileObject.doGetOutputStream`,  
if there is a exception on the method `channel.put`, use the 
`getAbstractFileSystem().putChannel(channel)` to return the channel to the pool.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to