Best Solutions: Connecting to FTP via JavaScript in NeoLoad


During your load test, you may want your virtual user to connect to an FTP server to upload or download some files. This can be done through a NeoLoad JavaScript. Here is an example of how to use FTP within a JavaScript using the FTPClient packages. FTPClient encapsulates all the functionality necessary to store and retrieve files from an FTP server.

We have provided the basics to send and receive a file, create and change directories, etc.

See a full list of FTPClient commands:

The Best Solution for you to Consider

Copy and paste these code snippets into a skeleton JavaScript in your user path.

NOTE: It is always required to have the Initialization routine placed first to connect to your FTP server before performing the additional actions.  Also, note that it’s recommended to include myFTPClient.logout(); and myFTPClient.disconnect(); at the end of your script to close your session’s connection.

// Initialization (required to connect, fill in servername, username and password)

myFTPClient =new; myFTPClient.connect(“servername”); myFTPClient.login(“username”,”password”); logger.debug(myFTPClient.getReplyCode()+” “+myFTPClient.getReplyString());

//Create a new folder with MKDIR command

myFTPClient.makeDirectory(“FTPNeoload”); logger.debug(myFTPClient.getReplyCode()+” “+myFTPClient.getReplyString());

//Change directory command
myFTPClient.changeWorkingDirectory(“FTPNeoload”); logger.debug(myFTPClient.getReplyCode()+” “+myFTPClient.getReplyString());

NOTE: Using PUT or GET methods may require switching your FTP connection into passive transfer mode. To do that add this one line command:

// Put FTP file transfer into passive mode


//Use of the GET method

var writer = new“c:\\Temp\\”,true);



logger.debug(myFTPClient.getReplyCode()+” “+myFTPClient.getReplyString());

//Use of the PUT method

var reader = new“c:\\Temp\\myfile.xps”); myFTPClient.storeFile(“myfile.xps”,reader);


logger.debug(myFTPClient.getReplyCode()+” “+myFTPClient.getReplyString());

//Command PWD (Print Working Directory)

myFTPClient.printWorkingDirectory(); logger.debug(myFTPClient.getReplyCode()+” “+myFTPClient.getReplyString());

//Command LIST

engine =myFTPClient.initiateListParsing(“/”);

while (engine.hasNext())


file = engine.getNext(5);



For more information, click here.

Next Steps: Review Documentation or Talk to Us

  • Check out all of the content included within NeoLoad documentation.
  • Want to discuss further, contact support.

Learn More about Performance Testing & Load Testing

Discover more load testing and performance testing content on the Neotys Resources pages, or download the latest version of NeoLoad and start testing today.

Leave a Reply

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