{"id":10074,"date":"2013-04-04T15:26:42","date_gmt":"2013-04-04T09:56:42","guid":{"rendered":"https:\/\/2thenew.xyz\/blog\/?p=10074"},"modified":"2013-07-13T11:34:24","modified_gmt":"2013-07-13T06:04:24","slug":"using-ftp-with-grails","status":"publish","type":"post","link":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/","title":{"rendered":"Using Ftp with Grails"},"content":{"rendered":"<p>In one of my Grails project I need to drop files over ftp server. Using\u00a0<a title=\"JSch\" href=\"http:\/\/www.jcraft.com\/jsch\/\" target=\"_blank\">JSch<\/a>\u00a0one can easily transfer files over sftp. Just follow the below steps.<br \/>\n1. Add the below dependency to Grails project <em>&#8220;grails-app\/conf\/BuildConfig.groovy&#8221;<\/em> file<\/p>\n<p>[sourcecode language=&#8221;groovy&#8221;]<br \/>\ndependencies {<br \/>\n        compile &#8216;com.jcraft:jsch:0.1.49&#8217;<br \/>\n    }<br \/>\n[\/sourcecode]<\/p>\n<p>2. Create a class for adding ftp credentials information. e.g. &#8220;FtpCredentail&#8221;<\/p>\n<p>[sourcecode language=&#8221;groovy&#8221;]<br \/>\nclass FtpCredential {<\/p>\n<p>    String server<br \/>\n    String username<br \/>\n    String password<br \/>\n    String remoteBaseDir<br \/>\n    Integer port<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p>3. Create a service named &#8220;FtpService&#8221; and add the following code into it<\/p>\n<p>[sourcecode language=&#8221;groovy&#8221;]<br \/>\nimport com.jcraft.jsch.Channel<br \/>\nimport com.jcraft.jsch.ChannelSftp<br \/>\nimport com.jcraft.jsch.JSch<br \/>\nimport com.jcraft.jsch.Session<\/p>\n<p>class FtpService {<br \/>\n    def grailsApplication<\/p>\n<p>    static transactional = true<\/p>\n<p>    def save(InputStream inputStream, String fileName, FtpCredential ftpCredential) {<br \/>\n        connect(ftpCredential) { ChannelSftp sftp -&gt;<br \/>\n            sftp.put inputStream, fileName<br \/>\n        }<br \/>\n    }<\/p>\n<p>    def load(String fileName, FtpCredential ftpCredential) {<br \/>\n        connect(ftpCredential, { ChannelSftp sftp -&gt;<br \/>\n            File outputFile = File.createTempFile(fileName,&#8221;)<br \/>\n            outputFile?.newOutputStream() &lt;&lt; sftp.get(fileName)<br \/>\n            outputFile<br \/>\n        }, false)<br \/>\n    }<\/p>\n<p>    def delete(String fileName, FtpCredential ftpCredential) throws Throwable {<br \/>\n        connect(ftpCredential) { ChannelSftp sftp -&gt;<br \/>\n            sftp.rm fileName<br \/>\n        }<br \/>\n    }<\/p>\n<p>    def makeDir(String directoryName, FtpCredential ftpCredential) {<br \/>\n        connect(ftpCredential) { ChannelSftp sftp -&gt;<br \/>\n            sftp.mkdir directoryName<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private def connect(FtpCredential ftpCredential, Closure c, boolean disconnectOnFinish = true) {<br \/>\n        Session session = null<br \/>\n        ChannelSftp sftp = null<br \/>\n        try {<br \/>\n            JSch jSch = new JSch()<br \/>\n            session = jSch.getSession username, ftpCredential?.server, ftpCredential?.port<br \/>\n            session.setConfig &quot;StrictHostKeyChecking&quot;, &quot;no&quot;<br \/>\n            File keyFile = new File(&quot;${grailsApplication.config.pathToKeyFile}&quot;)<br \/>\n            if (ftpCredential?.password) {<br \/>\n                session.password = ftpCredential?.password<br \/>\n            } else {<br \/>\n                jSch.addIdentity(keyFile?.absolutePath)<br \/>\n            }<br \/>\n            session.connect()<br \/>\n            Channel sFtpChannel = session.openChannel &quot;sftp&quot;<br \/>\n            sFtpChannel.connect()<br \/>\n            sftp = sFtpChannel as ChannelSftp<br \/>\n            sftp.cd ftpCredential?.remoteBaseDir<br \/>\n            c.call sftp<br \/>\n        } catch (Exception ex) {<br \/>\n            ex.printStackTrace()<br \/>\n        } finally {<br \/>\n            if (disconnectOnFinish) {<br \/>\n                sftp?.exit()<br \/>\n                session?.disconnect()<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\n<strong>Note:<\/strong> In the above code at <em>line number 44<\/em>.<br \/>\n[sourcecode language=&#8221;groovy&#8221;]<br \/>\nFile keyFile = new File(&quot;${grailsApplication.config.pathToKeyFile}&quot;)<br \/>\n[\/sourcecode]<br \/>\nThe code looks for private key provided by ftp server for password-less log in. One should define the property named &#8220;<em>pathToKeyFile<\/em>&#8221; in &#8220;<em>grails-app\/conf\/Config.groovy<\/em>&#8221; with value equals to the path of key file.<br \/>\n<br \/>\nNow you are ready to use the newly created FtpService service methods. Such as:<\/p>\n<ol>\n<li><em>save(inputStream, fileName, ftpCredential)<\/em> for saving file over ftp.<\/li>\n<li><em>load(fileName, ftpCredential)<\/em> for getting file from ftp.<\/li>\n<li><em>delete(fileName, ftpCredential)<\/em> for deleting file over ftp.<\/li>\n<li><em>makeDir(directoryName, ftpCredential)<\/em> for creating directory over ftp.<\/li>\n<\/ol>\n<h2>Example<\/h2>\n<p>For saving file over ftp one can use FtpService <strong>save<\/strong> method as shown below<br \/>\n[sourcecode language=&#8221;groovy&#8221;]<br \/>\n File file = File.createTempFile(&quot;temp&quot;,&quot;txt&quot;)<br \/>\n FtpCredential ftpCredential = new FtpCredential(server: &lt;server&gt;, username: &lt;username&gt;, password: &lt;password&gt;, port: &lt;server_port&gt;, remoteBaseDir: &lt;remote_base_directory&gt;)<br \/>\n InputStream inputStream = new BufferedInputStream(new FileInputStream(file))<br \/>\n ftpService.save(inputStream, &quot;fileNameToBeSavedOverFTPServer&quot;, ftpCredential)<br \/>\n[\/sourcecode]<br \/>\n<br \/>\n<em>Please share your feedback and suggestions.<\/em><\/p>\n<hr \/>\n<p style=\"text-align: right\"><strong><em><a title=\"JSch Examples\" href=\"http:\/\/www.jcraft.com\/jsch\/examples\/\" target=\"_blank\">Click here to read more <em>JSch<\/em> examples \u00bb<\/a><\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my Grails project I need to drop files over ftp server. Using\u00a0JSch\u00a0one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project &#8220;grails-app\/conf\/BuildConfig.groovy&#8221; file [sourcecode language=&#8221;groovy&#8221;] dependencies { compile &#8216;com.jcraft:jsch:0.1.49&#8217; } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. &#8220;FtpCredentail&#8221; [&hellip;]<\/p>\n","protected":false},"author":57,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":20,"footnotes":""},"categories":[7],"tags":[815,4840,9,1154,1153,1152,553],"class_list":["post-10074","post","type-post","status-publish","format-standard","hentry","category-grails","tag-ftp","tag-grails","tag-groovy","tag-jcraft","tag-jsch","tag-sftp","tag-ssh"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project &quot;grails-app\/conf\/BuildConfig.groovy&quot; file [sourcecode language=&quot;groovy&quot;] dependencies { compile &#039;com.jcraft:jsch:0.1.49&#039; } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. &quot;FtpCredentail&quot;\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Puneet Behl\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Using Ftp with Grails | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project &quot;grails-app\/conf\/BuildConfig.groovy&quot; file [sourcecode language=&quot;groovy&quot;] dependencies { compile &#039;com.jcraft:jsch:0.1.49&#039; } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. &quot;FtpCredentail&quot;\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Using Ftp with Grails | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project &quot;grails-app\/conf\/BuildConfig.groovy&quot; file [sourcecode language=&quot;groovy&quot;] dependencies { compile &#039;com.jcraft:jsch:0.1.49&#039; } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. &quot;FtpCredentail&quot;\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#article\",\"name\":\"Using Ftp with Grails | TO THE NEW Blog\",\"headline\":\"Using Ftp with Grails\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/puneet-behl\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2013-04-04T15:26:42+05:30\",\"dateModified\":\"2013-07-13T11:34:24+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":5,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#webpage\"},\"articleSection\":\"Grails, ftp, Grails, Groovy, jcraft, Jsch, sftp, ssh\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#listItem\",\"name\":\"Using Ftp with Grails\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#listItem\",\"position\":3,\"name\":\"Using Ftp with Grails\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/puneet-behl\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/puneet-behl\\\/\",\"name\":\"Puneet Behl\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/9b6468fa-13e0-4dbc-8a73-9fa9d1ecf84e_puneet.behl@tothenew.com.jpg\",\"width\":96,\"height\":96,\"caption\":\"Puneet Behl\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/\",\"name\":\"Using Ftp with Grails | TO THE NEW Blog\",\"description\":\"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project \\\"grails-app\\\/conf\\\/BuildConfig.groovy\\\" file [sourcecode language=\\\"groovy\\\"] dependencies { compile 'com.jcraft:jsch:0.1.49' } [\\\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. \\\"FtpCredentail\\\"\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/using-ftp-with-grails\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/puneet-behl\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/puneet-behl\\\/#author\"},\"datePublished\":\"2013-04-04T15:26:42+05:30\",\"dateModified\":\"2013-07-13T11:34:24+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Using Ftp with Grails | TO THE NEW Blog","description":"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project \"grails-app\/conf\/BuildConfig.groovy\" file [sourcecode language=\"groovy\"] dependencies { compile 'com.jcraft:jsch:0.1.49' } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. \"FtpCredentail\"","canonical_url":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#article","name":"Using Ftp with Grails | TO THE NEW Blog","headline":"Using Ftp with Grails","author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/puneet-behl\/#author"},"publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"},"datePublished":"2013-04-04T15:26:42+05:30","dateModified":"2013-07-13T11:34:24+05:30","inLanguage":"en-US","commentCount":5,"mainEntityOfPage":{"@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#webpage"},"isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#webpage"},"articleSection":"Grails, ftp, Grails, Groovy, jcraft, Jsch, sftp, ssh"},{"@type":"BreadcrumbList","@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","position":1,"name":"Home","item":"https:\/\/2thenew.xyz\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/2thenew.xyz\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#listItem","name":"Using Ftp with Grails"},"previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#listItem","position":3,"name":"Using Ftp with Grails","previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/2thenew.xyz\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/2thenew.xyz\/blog\/"},{"@type":"Person","@id":"https:\/\/2thenew.xyz\/blog\/author\/puneet-behl\/#author","url":"https:\/\/2thenew.xyz\/blog\/author\/puneet-behl\/","name":"Puneet Behl","image":{"@type":"ImageObject","@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/9b6468fa-13e0-4dbc-8a73-9fa9d1ecf84e_puneet.behl@tothenew.com.jpg","width":96,"height":96,"caption":"Puneet Behl"}},{"@type":"WebPage","@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#webpage","url":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/","name":"Using Ftp with Grails | TO THE NEW Blog","description":"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project \"grails-app\/conf\/BuildConfig.groovy\" file [sourcecode language=\"groovy\"] dependencies { compile 'com.jcraft:jsch:0.1.49' } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. \"FtpCredentail\"","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/#breadcrumblist"},"author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/puneet-behl\/#author"},"creator":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/puneet-behl\/#author"},"datePublished":"2013-04-04T15:26:42+05:30","dateModified":"2013-07-13T11:34:24+05:30"},{"@type":"WebSite","@id":"https:\/\/2thenew.xyz\/blog\/#website","url":"https:\/\/2thenew.xyz\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Using Ftp with Grails | TO THE NEW Blog","og:description":"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project &quot;grails-app\/conf\/BuildConfig.groovy&quot; file [sourcecode language=&quot;groovy&quot;] dependencies { compile 'com.jcraft:jsch:0.1.49' } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. &quot;FtpCredentail&quot;","og:url":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/","og:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Using Ftp with Grails | TO THE NEW Blog","twitter:description":"In one of my Grails project I need to drop files over ftp server. Using JSch one can easily transfer files over sftp. Just follow the below steps. 1. Add the below dependency to Grails project &quot;grails-app\/conf\/BuildConfig.groovy&quot; file [sourcecode language=&quot;groovy&quot;] dependencies { compile 'com.jcraft:jsch:0.1.49' } [\/sourcecode] 2. Create a class for adding ftp credentials information. e.g. &quot;FtpCredentail&quot;","twitter:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"10074","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-30 08:08:02","updated":"2024-02-29 10:52:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUsing Ftp with Grails\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/2thenew.xyz\/blog"},{"label":"Grails","link":"https:\/\/2thenew.xyz\/blog\/category\/grails\/"},{"label":"Using Ftp with Grails","link":"https:\/\/2thenew.xyz\/blog\/using-ftp-with-grails\/"}],"_links":{"self":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/10074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/users\/57"}],"replies":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/comments?post=10074"}],"version-history":[{"count":0,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/10074\/revisions"}],"wp:attachment":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/media?parent=10074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/categories?post=10074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/tags?post=10074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}