Uploading a file to an FTP server

Related to http://jobinandjismi.in/create-a-connection-with-an-ftp-server/
After creating a connection, you can transfer files to that server.

Solution

//Establishing connection to FTP is given in that above KB
var connection = sftp.createConnection({
                    username: userName,
                    passwordGuid: passGUID,
                    url: URL,
                    directory: '/',
                    hostKey: hostKey
                });
//if you have a xml content or json content, create them as a file and upload to FTP 
//Module: N/file :> file
var FileToUpload = file.create({
                        fileType: file.Type.PLAINTEXT,
                        name: XMLfileName,
                        contents: soData, //here soData refers to a xml body

                    });
connection.upload({
                        directory: '/Outbox/To be Processed', //directory of FTP to upload
                        file: FileToUpload,
                        filename: XMLfileName,
                        replaceExisting: true
                    });

Leave a comment

Your email address will not be published. Required fields are marked *