jsch example

来源:互联网 发布:linux下串口怎么测试 编辑:程序博客网 时间:2024/05/11 16:04

import com.jcraft.jsch.Channel
import com.jcraft.jsch.ChannelSftp
import com.jcraft.jsch.JSch
import com.jcraft.jsch.Session
import com.jcraft.jsch.UserInfo

 

public void syncLogs(hostname, username, password, port, remoteFile, localFile)
    {
        println "sync file " + remoteFile + " from server " + hostname
        JSch jsch = new JSch()
        Session session = jsch.getSession(username, hostname, port)
        session.setPassword(password)
        def config = new Properties()
        config.put("StrictHostKeyChecking", "no")
        session.setConfig(config)
        session.connect()

        Channel channel = session.openChannel("sftp")
        channel.connect()
        ChannelSftp c = (ChannelSftp)channel

        c.get(remoteFile, localFile)
        //c.put(localFile, remoteFile)
        session.disconnect()
    }

原创粉丝点击