//******************************************************************* // SFtpFrom - SSH File Transfer Protocol // // The SSH File Transfer Protocol (SFTP) is used to securely transfer computer // files between a client and server on a computer network // // For more information about Aqua Open API visit link: http://docs.aquafold.com/ads/18.0/openapi/ //******************************************************************* //******************************************************************* // Input parameters. //******************************************************************* var host = "test98.brickftp.com"; // The hostname or IP address of the remote server that you are connecting to. var file = "/Users/kinhong/temp/image003.png"; // The files to download from the remote server to the local machine. var toDirectory = "C:/Users/Meghanth/Desktop/DB2LUW"; // The directory on the local machine where the files are to be saved. var username = "kinhong.wong@gmail.com"; // The username on the remote server that you are connecting to. /** The password for the remote server. For password, provide a password or the name of secure storage created in Aqua Data Studio. To create secure storage in Aqua Data Studio go to File-->Options-->Secure storage-->Add. You can also prompt for a password in the console at script execution time by uncommenting the password prompt call below. **/ var password = "asdfasdf"; var keyFile = ""; // Location of the file holding the private key. var passphrase = ""; // Passphrase for your private key. var trust = true; // Trusts all unknown hosts if set to true. Defaults to false. var knownHosts = ""; // Sets the known hosts file used to validate the identity of the remote server. checkParameters( host, file, toDirectory, username, keyFile, password, trust); executeSftpFrom( file, toDirectory, host, username, password, keyFile, passphrase, trust, knownHosts); //******************************************************************* // This function checks for empty parameters. //******************************************************************* function checkParameters( host, file, toDirectory, username, keyFile, password, trust) { if (host === "") { showMessage("Please enter the hostname or IP address of the remote server that you are connecting to."); } if (file === "") { showMessage("Please enter the directory on the remote server where the files are to be downloaded from."); } if (toDirectory === "") { showMessage("Please enter the path of the local directory where the files are to be downloaded to."); } if (username === "") { showMessage("Please enter value for the username on the remote server that you are connecting to."); } if (trust === null) { showMessage("Please enter value for trust. The value can be either true or false."); } if (keyFile === "" && password === "") { /** Use the following call to prompt for a password in the console at script execution time. Comment out the following showMessage call also. this.password = aqua.console.readPassword("Password: "); **/ showMessage("Please enter valid path for the key file or a valid secure storage value or the actual password."); } } //******************************************************************* // This function executes the sftpFrom API to download files from a remote server. //******************************************************************* function executeSftpFrom( file, toDirectory, host, username, password, keyFile, passphrase, trust, knownHosts) { try { /** Use this sftp call if you are using secure storage to store the password. To create secure storage in Aqua Data Studio go to File-->Options-->Secure storage-->Add. aqua.net.sftpFrom(file, toDirectory, host, username, aqua.crypto.getSecureField(password), keyFile, passphrase, trust, knownHosts); **/ //Use this sftp call if you are using a regular password aqua.net.sftpFrom(file, toDirectory, host, username, password, keyFile, passphrase, trust, knownHosts); showMessage("File transfer is successful from the server : "+host); } catch(ex) { showError(" sftpFrom() File(s) transfer failed. Cause: \n ", ex); } } //******************************************************************* // A utility function to write a message to the console. //******************************************************************* function showMessage(message) { aqua.console.println(message); } //******************************************************************* // A utility function to report errors. //******************************************************************* function showError(command, exception) { showMessage(command + exception.name + " : " + exception.message); }