简体   繁体   中英

Equivalent Scala code for Java code

I am new to scala.Any one having idea what is the equivalent code in scala for the following java code

package sampleFTP
import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
import com.jcraft.jsch._
object FTPTest {



 def main(args: Array[String]) {
      println("Hello, world!")
      var ftpClient= new FTPClient();


    val SFTPPASS = "xxxx";
    val SFTPWORKINGDIR = "/xxxx/xxxx";


    System.out.println("preparing the host information for sftp.");

 val jsch = new JSch();
        var session = jsch.getSession("xxxx", "xxxx", 22)
        session.setPassword(SFTPPASS);
        var config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();
        System.out.println("Host connected.");
        var channel = session.openChannel("sftp");
        channel.connect();
        System.out.println("sftp channel opened and connected.");


       var sftpChannel = (ChannelSftp) session.openChannel("sftp");//error in this line
        System.out.println("Directory:" + sftpChannel.pwd());

        session.disconnect();
  }

}

I am getting the following error

value session is not a member of object com.jcraft.jsch.ChannelSftp

I have Successfully implemented the secure FTP connection using jsch .How to download and list file via jsch in scala .

要在 Scala 中转换为不同的类型,请使用:

session.openChannel("sftp").asInstanceOf[ChannelSftp]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM