-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File is getting corrupted when Chunk Mode file transfer interrupted #315
base: master
Are you sure you want to change the base?
Changes from 2 commits
7c13d8e
f55eaae
9aee720
8d05634
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ | |
import java.util.Hashtable; | ||
import java.util.Vector; | ||
|
||
import com.jcraft.jsch.Channel.MyPipedInputStream; | ||
|
||
|
||
public class ChannelSftp extends ChannelSession { | ||
|
||
static private final int LOCAL_MAXIMUM_PACKET_SIZE = 32 * 1024; | ||
|
@@ -158,6 +161,7 @@ public class ChannelSftp extends ChannelSession { | |
private boolean fEncoding_is_utf8 = true; | ||
|
||
private RequestQueue rq = new RequestQueue(16); | ||
private String chunkStart = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it to Long now and made the other changes accordingly. |
||
|
||
/** | ||
* Specify how many requests may be sent at any one time. Increasing this value may slightly | ||
|
@@ -516,7 +520,13 @@ public void _put(InputStream src, String dst, SftpProgressMonitor monitor, int m | |
// System.err.println(eee); | ||
} | ||
} | ||
if (mode == RESUME && skip > 0) { | ||
if((mode==RESUME&& chunkStart!=null) && skip>0){ | ||
long skipped=src.skip(skip-Long.parseLong(chunkStart)); | ||
if(skipped<(skip-Long.parseLong(chunkStart))){ | ||
throw new SftpException(SSH_FX_FAILURE, "failed to resume for "+dst); | ||
} | ||
} | ||
else if(mode==RESUME && skip>0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this could be better written as simply something like this to avoid code duplication:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have made the changes as suggested. |
||
long skipped = src.skip(skip); | ||
if (skipped < skip) { | ||
throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + dst); | ||
|
@@ -643,6 +653,32 @@ public void _put(InputStream src, String dst, SftpProgressMonitor monitor, int m | |
throw (SftpException) e; | ||
throw new SftpException(SSH_FX_FAILURE, e.toString(), e); | ||
} | ||
|
||
public boolean checkChunkFailed(InputStream src, String dst, String ChunkStart)throws SftpException{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
try{ | ||
((MyPipedInputStream)io_in).updateReadSide(); | ||
|
||
byte[] dstb=Util.str2byte(dst, fEncoding); | ||
long skip=0; | ||
try{ | ||
SftpATTRS attr=_stat(dstb); | ||
skip=attr.getSize(); | ||
} | ||
catch(Exception eee){ | ||
//System.err.println(eee); | ||
} | ||
|
||
if(skip>0){ | ||
if(skip == Long.parseLong(ChunkStart)) | ||
return false; | ||
else return true; | ||
} | ||
else return false; | ||
} | ||
catch(Exception e){ | ||
throw new SftpException(SSH_FX_FAILURE, "Cannot check-" + e.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
} | ||
|
||
public OutputStream put(String dst) throws SftpException { | ||
|
@@ -2952,6 +2988,10 @@ public String realpath(String path) throws SftpException { | |
throw (SftpException) e; | ||
throw new SftpException(SSH_FX_FAILURE, e.toString(), e); | ||
} | ||
} | ||
|
||
public void setChunkStart(String chunkStart) { | ||
this.chunkStart= chunkStart; | ||
} | ||
|
||
public static class LsEntry implements Comparable<LsEntry> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,8 @@ public class Session { | |
|
||
Buffer buf; | ||
Packet packet; | ||
|
||
List<String> fingerprintList = new ArrayList<String>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be shortened to simply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it as suggested. |
||
|
||
SocketFactory socket_factory = null; | ||
|
||
|
@@ -883,9 +885,20 @@ private void checkHost(String chost, int port, KeyExchange kex) throws JSchExcep | |
} | ||
// System.err.println("finger-print: "+key_fprint); | ||
if (userinfo != null) { | ||
if (shkc.equals("ask")) { | ||
boolean foo = userinfo.promptYesNo("The authenticity of host '" + chost | ||
+ "' can't be established.\n" + key_type + " key fingerprint is " + key_fprint + ".\n" | ||
+ "Are you sure you want to continue connecting?"); | ||
} else { | ||
anamikagsingh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
boolean foo = false; | ||
for(String eachFingerPrint : fingerprintList){ | ||
if(key_fprint.equalsIgnoreCase(eachFingerPrint)) | ||
{ | ||
foo = true; | ||
break; | ||
} | ||
} | ||
} | ||
anamikagsingh marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, can you point at any other applications or libraries that perform SSH host key verification using fingerprints? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea if any other application which is using Jsch library is also using fingerprints to perform SSH host key verification. It is being used in SAP PI SFTP Adapter. |
||
if (!foo) { | ||
throw new JSchException("reject HostKey: " + chost); | ||
} | ||
|
@@ -3198,6 +3211,12 @@ private void checkConfig(ConfigRepository.Config config, String key) { | |
if (value != null) | ||
this.setConfig(key, value); | ||
} | ||
|
||
public void addToFingerprintList(String channelFingerprint) | ||
{ | ||
String []fingerprints = channelFingerprint.split("~"); | ||
anamikagsingh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.fingerprintList = new ArrayList<String>(Arrays.asList(fingerprints)); | ||
} | ||
|
||
/** | ||
* Returns the logger being used by this instance of Session. If no particular logger has been | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,8 @@ public boolean start(Session session) throws Exception { | |
byte[][] response = null; | ||
|
||
if (password != null && prompt.length == 1 && !echo[0] | ||
&& prompt[0].toLowerCase().indexOf("password:") >= 0) { | ||
&& (prompt[0].toLowerCase().indexOf("password:") >= 0 | ||
|| prompt[0].toLowerCase().indexOf("password") >= 0)){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #302 you mention that this change is needed in order to support a server that has a prompt of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not able to reproduce this issue in my test system so cannot test it. We can leave the changes done in UserAuthKeyboardInteractive.java for now. Please let me know if I need to revert the changes and commit again. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are not able to reproduce the issue that you believed was fixed by this change, then it should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The or also overlaps, you could just remove the colon.. |
||
response = new byte[1][]; | ||
response[0] = password; | ||
password = null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary.
Since
ChannelSftp
extendsChannel
, it can directly reference theMyPipedInputStream
class without an import statement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the import as it was not needed. Thanks for the suggestions.