I am using JSch to perform an SFTP download in Android. This is on a LAN with 802.11n and an SFTP server on a wired gigabit connection. I am getting about 8 mbytes/sec on a laptop (also 802.11n) with the same code but I am only getting 40kbytes/sec on Android. Are there some flags or something I need to turn on to get this to transfer faster? I have tried it on a Nexus 5 and a Nexus 6, both with Android 5.1. I also tried a couple of apps and one downloaded the file at 230kbytes/sec and the other right around 40kbytes/sec so I'm guessing one of them has the same issue I do.
My test code is this:
public class MainActivity extends ActionBarActivity {
@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Threadthread=newThread(){@Overridepublicvoidrun(){try{JSchjsch=newJSch();jsch.setConfig("StrictHostKeyChecking","no");Sessionsession=jsch.getSession("ftptest","192.168.1.205");session.setPort(22);session.setPassword("password");session.connect();ChannelSftpchannel=(ChannelSftp)session.openChannel("sftp");channel.connect();SftpProgressMonitormonitor=newSftpProgressMonitor(){longfinalCount=0;longstart=-1;@Overridepublicvoidinit(intop,Stringsrc,Stringdest,longmax){start=System.currentTimeMillis();}@Overridepublicbooleancount(longcount){finalCount+=count;/* long took = (System.currentTimeMillis() - start) / 1000; if (took > 0) { Log.w("SFTP", "Transferred so far " + finalCount + " at speed bytes/sec " + (finalCount / took)); }*/returntrue;}@Overridepublicvoidend(){longtook=(System.currentTimeMillis()-start)/1000;Log.w("SFTP","Transferred "+finalCount+" in "+took+" speed bytes/sec "+(finalCount/took));}};InputStreamstream=channel.get("file",monitor);intread=-1;byte[]bs=newbyte[8192];while((read=stream.read(bs))>=0){//donothing}}catch(JSchExceptione){e.printStackTrace();}catch(SftpExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}}};thread.start();}}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like to add that it is a lot faster, about 160kbytes/sec if I use the get method that writes into a file directly instead of giving me an input stream. It is still a lot slower than running it outside Android though.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using JSch to perform an SFTP download in Android. This is on a LAN with 802.11n and an SFTP server on a wired gigabit connection. I am getting about 8 mbytes/sec on a laptop (also 802.11n) with the same code but I am only getting 40kbytes/sec on Android. Are there some flags or something I need to turn on to get this to transfer faster? I have tried it on a Nexus 5 and a Nexus 6, both with Android 5.1. I also tried a couple of apps and one downloaded the file at 230kbytes/sec and the other right around 40kbytes/sec so I'm guessing one of them has the same issue I do.
My test code is this:
public class MainActivity extends ActionBarActivity {
I would like to add that it is a lot faster, about 160kbytes/sec if I use the get method that writes into a file directly instead of giving me an input stream. It is still a lot slower than running it outside Android though.