package com.hai.linux;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.SCPClient;
import ch.ethz.ssh2.SCPOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class scpConnection {
    public static void main(String[] args) {
        Connection connection = new Connection("xxx.xxx.xxx.xx",22);
        String filePath1 ="testlinux/aa1.txt" ;
        File f = new File(filePath1);
        try(FileInputStream fis = new FileInputStream(f)){
            connection.connect();
            boolean isAuthenticated = connection.authenticateWithPassword("root","xxx");
            if(!isAuthenticated){
                System.out.println("连接建立失败");
                return ;
            }
            SCPClient scpClient = new SCPClient(connection);
            String remoteTargetDirectory = "/data5";
//            SFTPv3Client sftpv3Client = new SFTPv3Client(connection);
            SCPOutputStream os = scpClient.put(f.getName(),f.length(),remoteTargetDirectory,null);
            byte[] b = new byte[4096];
            int i;
            while ((i = fis.read(b)) != -1) {
                os.write(b, 0, i);
            }
//            scpClient.put("testlinux/aa1.txt","/data5");
            os.flush();
            fis.close();
            os.close();
            connection.close();
            System.out.println("upload ok");
        }catch (IOException e) {
        e.printStackTrace();
        }
    }
}
最近下载更多
                
                qiheideguang     LV18
                2024年7月24日
            
            
        
                438265764     LV14
                2023年7月31日
            
            
        
                15866685272     LV3
                2023年5月4日
            
            
        
                林间听风     LV10
                2023年2月1日
            
            
        
                lironggang     LV38
                2022年11月20日
            
            
        
                lxsnh123     LV3
                2022年11月18日
            
            
        
                skipple3     LV39
                2022年10月18日
            
            
        
                zw050256     LV7
                2022年9月30日
            
            
        
                wuyu8995861     LV7
                2022年8月8日
            
            
        
                liuyu-zui     LV4
                2022年8月1日
            
            
        
最近浏览更多
                
                xp95323     LV15
                6月10日
            
            
        
                qiheideguang     LV18
                2024年7月24日
            
            
        
                zhyoyu    
                2024年5月20日
            
            
                    暂无贡献等级
            
        
                微信网友_6902352269217792     LV3
                2024年3月12日
            
            
        
                LARY     LV1
                2024年1月5日
            
            
        
                tangjianzhong    
                2023年12月19日
            
            
                    暂无贡献等级
            
        
                kkkxyh     LV13
                2023年12月11日
            
            
        
                jiemomo     LV12
                2023年10月19日
            
            
        
                19050126312     LV1
                2023年10月19日
            
            
        
                2036495585     LV9
                2023年9月25日
            
            
        
                
                
                