#53 i can not copy file

open
nobody
None
5
2014-08-15
2011-05-24
li zhaojin
No

ChannelSftp not have copy function ,I write it ,use get and put method ,but it have some problem ,see code below

i don't think write a temp file or store all the data in the memory is good idear

public void copyFile(String serverSourceFile,String serverDestFile) throws Exception
{
/*
InputStream in=this.sftp.get(serverSourceFile);
this.sftp.put(in,serverDestFile);//here is blocking
*/

InputStream input=this.sftp.get(serverSourceFile);
OutputStream output=this.sftp.put(serverDestFile);
try
{
byte[] buffer=new byte[1024*10];
int len=0;
while((len=input.read(buffer))!=-1)
{
System.out.println(len);
//output.write(buffer,0,len);// i can not do this , i think ,the get and put method use same buffer
}
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
input.close();
output.close();
}catch(Exception e)
{
//e.printStackTrace();
}

}
}

Discussion