Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SFTP simple Download Java with ScriptMaster

Featured Replies

Same comments as the upload basically.

There's some FTP code posted but here's a basic SFTP version. Feel free to correct me or add to it and post.

Some elements actually might not be needed or could be better written.

I'm not a programmer per se so be nice.....


/**********************************************************************************************************

* SFTP Download

* parameters sftp_hostname, sftp_username, sftp_password, sftp_port (should be 22 I believe)

*        remote_directorypath, remote_filename, local_directorypath, local_filename

*

* JSch is licensed under BSD style license.

* http://www.jcraft.com/jsch

* http://www.jcraft.com/jsch/examples/

* http://epaul.github.com/jsch-documentation/javadoc/

*

* Jar file: http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.44/jsch-0.1.44.jar/download

*

* Disclaimer: This code is provided as is without any guarantees,warranties or representations.

* User is responsible to verify all legalities

* Finally - This is just a base. Feel free to add to it and post.....

**********************************************************************************************/

import com.jcraft.jsch.*;

import java.io.*;



    JSch jsch = new JSch();

        Session session = null;



        String result_text = "";

        // Use External Function SMGetVariable( variableName ) to return to FM

        try {

            session = jsch.getSession(sftp_username, sftp_hostname, Integer.parseInt(sftp_port));

            session.setConfig("StrictHostKeyChecking", "no");

            session.setPassword(sftp_password);

            session.connect();



            Channel channel = session.openChannel("sftp");

            channel.connect();

            

            ChannelSftp sftpChannel = (ChannelSftp) channel;

            // Local folders with spaces, like Program Files, causes problems but I'm sure

            // someone with better coding skills can easily fix this I'm sure

            sftpChannel.get(remote_directorypath + remote_filename, local_directorypath + local_filename);



            sftpChannel.exit();

            session.disconnect();

            // check for file on local drive

            if (new File(local_directorypath + local_filename).exists()) {

                result_text = result_text + "Download Complete"; // returns to FM

            } else {

                result_text = result_text + "Download Failed"; // returns to FM

            }

        } catch (JSchException e) {

            result_text = result_text + e.printStackTrace(); // returns error to FM

        } catch (SftpException e) {

            result_text = result_text + e.printStackTrace(); // returns error to FM

        }

 

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.