-2

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.

dumbPotato21
  • 5,669
  • 5
  • 21
  • 34
arun
  • 106
  • 2
  • 11

1 Answers1

5

To cast to a different type in Scala use:

session.openChannel("sftp").asInstanceOf[ChannelSftp]
nmat
  • 7,430
  • 6
  • 30
  • 43