java-疑问-远程连接linux服务器找不到文件路径

连接后,遍历文件夹,打开其中一个文件报找不到文件路径,不知为何,待解

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();
        }

 

转载于:https://www.cnblogs.com/lely/p/10250488.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值