Skip to content

Using Variables in a GoAnywhere Project

View some of the Frequently Asked Questions to our support staff. Included are some tips and tricks making this forum ideal for users getting started with GoAnywhere MFT, Gateway, Agents, etc.
Note: Users can reply to existing topics but only our support staff can add new topics to this forum.
  • User avatar
  • Support_Rick Offline
  • Fortra Employee
  • Posts: 589
  • Joined: Tue Jul 17, 2012 2:12 pm
  • Location: Phoenix, AZ
  • Contact:

Using Variables in a GoAnywhere Project

Post by Support_Rick »

A variable is a name associated with a value. In GoAnywhere, a variable can hold a variety of values including numbers, file and folder names, IP addresses and more. You can pass in the values for variables from your applications or from other projects.

Using a Variable to override a File Name

A project outline is shown below which connects to a SFTP server and puts a file onto that server. See Figures 1 & 2.
Figure 1.png
Figure 1.png (8.95 KiB) Viewed 179 times

Notice how the Source File is hard coded with the file name of C:/temp/gademo.txt. This is not flexible if your file names change regularly.
Figure 2.png
Figure 2.png (16.77 KiB) Viewed 179 times

Instead of using a hard-coded value, you can use a variable in the SFTP PUT task to supply the file name. To do this, right-click on the Project Level in the Outline and select “Add a Variable.” Give the variable a name, “MyFile” and leave the initial value blank (See Figures 3 & 4).
Figure 3.png
Figure 3.png (11.3 KiB) Viewed 179 times
Figure 4.png
Figure 4.png (15.32 KiB) Viewed 179 times

Your project outline now has the variable MyFile added.
Figure 5.png
Figure 5.png (11.5 KiB) Viewed 179 times
You now need to add this variable to the PUT task Source File field. Variable names are wrapped with ${} when they are used as an input attribute in a task (See Figure 6).
Figure 6.png
Figure 6.png (24.21 KiB) Viewed 179 times

With this change, you can now run the project and pass the name of the file you want to transfer.
Passing parameters can be done several ways:
  1. Interactively
  2. From another Project
  3. From a Monitor Job
  4. From a Scheduled Job
  5. From a GoAnywhere Services Trigger
  6. From an External application using the GACmd API
For this example, we will execute this project interactively and use our variable to pass the file path and name. Click on the Cog button next to the project name, and then click the “Execute Advanced…” option (see Figure 7).
Figure 7.png
Figure 7.png (31.01 KiB) Viewed 179 times


This allows you to pass a value to the variable defined earlier within the project (see Figure 8).
Figure 8.png
Figure 8.png (18.75 KiB) Viewed 179 times

By filling in the File Path and Name, then clicking on the “Execute” button, you can then view the job log to see where ${MyFile} is created and set to the value “C:\Temp\GADemo2.txt.” You can also see that the file has been uploaded successfully (see Figure 9).

Figure 9
Figure 9.png
Figure 9.png (252 KiB) Viewed 179 times

The Source for this project is located below.

Code: Select all

<project name="Using Variables - Part 2" mainModule="Main" version="2.0" logLevel="verbose">
<variable name="MyFile" value="" />

	<module name="Main">

		<sftp label="Connect to Server" resourceId="Test SFTP" version="1.0">
			<put label="Put file on Target Server" 
sourceFile="${MyFile}" 
destinationDir="/Demos/inbound" />
		</sftp>

	</module>

	<description>Basic Project with Parameter</description>
	
</project>
Please feel free to contact Fortra at [email protected] with any questions or to inquire about our Professional Services or Training programs.
Rick Elliott
Solution Architect
(402) 944.4242
(800) 949-4696