by
0
4
4,963
77
Top 1% !
Popular
Famous
Specified
Popularity: 1483rd place
Created
Modified Mar 18, 2015

Published on:

No tags for this snippet yet.
LanguageGroovy
LicenseMIT_X11
SourceGitHub

SoapUI Groovy Script compatible SFTP file upload

SoapUI Groovy Script compatible SFTP file upload: 
groovySFTPfileupload
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/413499/SoapUI-Groovy-Script-compatible-SFTP-fil?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
@Grab(group='commons-net', module='commons-net', version='2.0') @Grab(group='com.jcraft', module='jsch', version='0.1.51') import org.apache.commons.net.ftp.FTPSClient import com.jcraft.jsch.*; ///////////////////////////////////////////////////////////// /////////////////////////Configs///////////////////////////// ///////////////////////////////////////////////////////////// String ftpdomain = "yourdomain.org" int ftpport = 22 String ftpusername = "username" String ftppassword = "password" String localfilelocation = "C:/Users/username/Desktop/123.html" String remotefilelocation = "/home/test" ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// try { log.info("Starting sftp upload process") Session session = null; Channel channel = null; JSch ssh = new JSch(); session = ssh.getSession(ftpusername, ftpdomain, ftpport); session.setConfig("StrictHostKeyChecking", "no"); //auto accept secure host session.setPassword(ftppassword); session.connect(); log.info("Connected to session") channel = session.openChannel("sftp"); channel.connect(); log.info("Connected to channel") ChannelSftp sftp = (ChannelSftp) channel; sftp.put(localfilelocation, remotefilelocation); log.info("File Uploaded " + localfilelocation + " TO " + remotefilelocation) } catch (JSchException e) { e.printStackTrace(); log.info("JSchException " + e.printStackTrace()) } catch (SftpException e) { e.printStackTrace(); log.info("SftpException " + e.printStackTrace()) } finally { if (channel != null) { channel.disconnect(); log.info("Disconnected from channel") } if (session != null) { session.disconnect(); log.info("Disconnected from session") } log.info("sftp upload process complete") }
If you want to be updated about similar snippets, Sign in and follow our Channels