Hi all,

first i'd like to thank JCraft for the JSch library. It has been really helpful 
so far!

But during my development i ran into a problem: trying to copy a file with SCP 
to an SFTP-Server
using the Streams provided by JSch. The error is easily reproducable in Version 
0.1.55 by doing
the following steps:

* Retrieve an InputStream (MyPipedInputStream) from a Channel
* Try to upload this file with an ChannelSftp:

--------
    JSch jsch = new JSch();
    Session session = jsch.getSession(username, host, port);
    ChannelExec channel = (ChannelExec) session.openChannel("exec");
    ...
    InputStream sshInputStream = channel.getInputStream();

    JSch jsch = new JSch();
    Session session = jsch.getSession(username, host, port);
    ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
   channel.put(sshInputStream , file);
--------

The problem lies in ChannelSftp's _put method (lines 635 to 643):

--------
    do{
        nread=src.read(data, s, datalen);
        if(nread>0){
            s+=nread;
            datalen-=nread;
            count+=nread;
        }
    }
    while(datalen>0 && nread>0);
--------

As far as i understand it, the while-loop tries to read as many bytes as 
possible into the data
array. But since a (My)PipedInputStream doesn't return -1 if it's empty, but 
rather waits for more
data to come, this ends in an endlessly blocking read() at the end of the file 
transfer.

The only way i could solve this is by removing the do-while-loop around the 
code and adding an
SftpProgressMonitor implementation, that returns false on count(long byte) if 
the whole file has
been transferred. But that involves manipulating JSch source code, which i'd 
prefer not to do...

Is there any better solution to this particular problem?

Any help would be greatly appreciated!

Thanks
Andreas
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to