Hi,
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
Stephan
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 @@
dst=(String)(v.elementAt(0));
}
- if(isRemoteDir(dst)){
- throw new SftpException(SSH_FX_FAILURE, dst+" is a directory");
- }
-
if(monitor!=null){
monitor.init(SftpProgressMonitor.PUT,
"-", 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());
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users