We are trying to upload files to a SFTP server with a virtual file system that shows some rather strange behavior, because there aren’t any directories in there but you can change to any directory name (and the server will reply that any directory exists, if you ask it). It turned out that we cannot put any files up there with jsch 0.1.48 because the put checks if a remote directory exists with the given filename before even trying the upload. If we remove this check as in the first patch below uploading to this SFTP server does work, however if you try to upload a file to a OpenSSH server with that patched version where a directory obstructs the filename of the file that is supposed to be uploaded, you get an SftpException with error code SSH_FX_FAILURE and the error string “Fault” (which is not so helpful, and most probably the reason why this check was introduced).


Therefore we have done a second patch that checks for the existence of the directory after the upload has failed and changes the error message accordingly. This version will behave the same as the original version for the OpenSSH server, but works with the SFTP server with the virtual filesystem.


Is this something to consider for the upstream?


Best regards



diff --git a/src/main/java/com/jcraft/jsch/ChannelSftp.java b/src/main/java/com/jcraft/jsch/ChannelSftp.java

index 2fbd69d..d4788a6 100644

--- a/src/main/java/com/jcraft/jsch/ChannelSftp.java

+++ b/src/main/java/com/jcraft/jsch/ChannelSftp.java

@@ -482,10 +482,6 @@



-      if(isRemoteDir(dst)){

-        throw new SftpException(SSH_FX_FAILURE, dst+" is a directory");

-      }




                      "-", dst,




diff --git a/src/main/java/com/jcraft/jsch/ChannelSftp.java b/src/main/java/com/jcraft/jsch/ChannelSftp.java

index d4788a6..99f2ecd 100644

--- a/src/main/java/com/jcraft/jsch/ChannelSftp.java

+++ b/src/main/java/com/jcraft/jsch/ChannelSftp.java

@@ -491,7 +491,12 @@

       _put(src, dst, monitor, mode);


     catch(Exception e){

-      if(e instanceof SftpException) throw (SftpException)e;

+      if(e instanceof SftpException){

+        SftpException se=(SftpException)e;

+        if((se.id==SSH_FX_FAILURE)&&isRemoteDir(dst))

+          throw new SftpException(SSH_FX_FAILURE, dst+" is a directory");

+        throw se;

+      }

       if(e instanceof Throwable)

         throw new SftpException(SSH_FX_FAILURE, e.toString(), (Throwable)e);

       throw new SftpException(SSH_FX_FAILURE, e.toString());