Pessoal, to usando o JSch p transferir um arquivo da minha app (win) p o servidor Linux. To usando o seguinte codigo de exemplo da JSch:
public class ScpTo{
public static void main(String[] arg){
FileInputStream fis=null;
try{
//usage: java ScpTo file1 user@remotehost:file2
String lfile="teste.txt";
String user="root";
String host="201.20.72.2";
String rfile="teste.txt";
JSch jsch=new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword("senha");
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo();
session.setUserInfo(ui);
session.connect();
// exec 'scp -t rfile' remotely
String command="scp -p -t "+rfile;
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
// get I/O streams for remote scp
OutputStream out=channel.getOutputStream();
InputStream in=channel.getInputStream();
channel.connect();
if(checkAck(in)!=0){
System.exit(0);
}
// send "C0644 filesize filename", where filename should not include '/'
long filesize=(new File(lfile)).length();
command="C0644 "+filesize+" ";
if(lfile.lastIndexOf('/')>0){
command+=lfile.substring(lfile.lastIndexOf('/')+1);
}
else{
command+=lfile;
}
command+="\n";
out.write(command.getBytes()); out.flush();
if(checkAck(in)!=0){
System.exit(0);
}
// send a content of lfile
fis=new FileInputStream(lfile);
byte[] buf=new byte[1024];
while(true){
int len=fis.read(buf, 0, buf.length);
if(len<=0) break;
out.write(buf, 0, len); //out.flush();
}
fis.close();
fis=null;
// send '\0'
buf[0]=0; out.write(buf, 0, 1); out.flush();
if(checkAck(in)!=0){
System.exit(0);
}
out.close();
channel.disconnect();
session.disconnect();
System.exit(0);
}
catch(Exception e){
System.out.println(e);
try{if(fis!=null)fis.close();}catch(Exception ee){}
}
}
....
Qnd executa, ele pede a senha do servidor, eu entro a msm de root, mas dar senha errada. Qnd tento executar o “psftp” “pscp” do putty, dar msm coisa, no “psftp” ainda dar “Acess Denied”. Engracado q essa senha de root ta pegando normal p se logar via ssh e executar comandos. Alguem sabe q está acontecendo? Será q eh alguma configuracao no servidor, liberacao d servico ou algo parecido? Me ajudem ai, to parado nisso, vlw…
Eu busquei topicos relacionados aqui no GUJ, mas n vi nd q pudesse me ajudar c este problema.