标签:Opens exception count sftp put 远程 out key 连接
连接后,遍历文件夹,打开其中一个文件报找不到文件路径,不知为何,待解
SshClient client=new SshClient(); try{ ConsoleKnownHostsKeyVerification console = new ConsoleKnownHostsKeyVerification(); client.connect("47.110.70.236",22,console); //设置用户名和密码 PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); pwd.setUsername("transnftp"); pwd.setPassword("tqhy@2019"); int result=client.authenticate(pwd); if(result==AuthenticationProtocolState.COMPLETE){//如果连接完成 //源文件地址OriginPath String OriginPath="/upload"; List<SftpFile> list = client.openSftpClient().ls(OriginPath); int filecount=0; for(SftpFile f:list) { //三个跨境电商 String eCommercePath=f.getAbsolutePath(); List<SftpFile> eCommercelist = client.openSftpClient().ls(eCommercePath); for(SftpFile ff:eCommercelist) { //取json结尾文件 //0bd4f4c81cc6a16e9a746f756ba52c9f.json if(ff.getFilename().endsWith(".json")) { SessionChannelClient session = client.openSessionChannel(); if(session.startShell()) { BufferedReader in = new BufferedReader(new InputStreamReader(session.getInputStream())); System.out.println("名称长度:"+ff.getFilename()); System.out.println("地址:"+ff.getAbsolutePath()); System.out.println(in.readLine()); } filecount++; break; } } } System.out.println("文件数为:"+filecount); } }catch(IOException e){ e.printStackTrace(); }
标签:Opens exception count sftp put 远程 out key 连接
原文地址:https://www.cnblogs.com/lely/p/10250488.html