Failure to reuse variable-defined resource in SFTP

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
3 posts Page 1 of 1

david_SD

Posts: 4
Joined: Thu Sep 11, 2014 9:28 am

Post by david_SD » Thu Sep 11, 2014 9:45 am
GoAnywhere Director seems to be having an issue with reusing a variable declared resourceId for an SFTP server.

I have an archiving job that reads an excel spreadsheet, where each row contains a different SFTP RESOURCE and PATH to purge files. The resource name in the spreadsheet is the string used to define/name the resource in GoAnywhere.

The main loop is:
Code: Select all
	<forEachLoop itemsVariable="${archivalConfig}" currentItemVariable="currArchivalObject">
	<setVariable name="resourceObj" value="${currArchivalObject["SRC_RESOURCE"]}" version="2.0" />

		<sftp resourceId="${resourceObj}" version="1.0" onError="continue">
			<delete>
				<fileset dir="${currArchivalObject["SRC_LOCATION"]}">
					<dateFilter>
						<include to="${DateFrom}" />
					</dateFilter>
				</fileset>
			</delete>
		</sftp>

	</forEachLoop>
I noticed that the system properly iterates through the itemsVariable for each record in my configuration spreadsheet. The first time through, it uses the server resource name "SERVER01" and uses it to purge files. When it hits the next record, it correctly reads in "SERVER02" and sets the resourceObj variable. But when the sftp statement is run the resourceId does not use the new value of the variable (resourceObj="SERVER02"), but uses "SERVER01". For each subsequent row, it updates the resourceObj variable correctly, but always uses the server that was specified the first time it was called.

I've tried to set the SFTP session ID and close it after the command, but the SFTP command still uses the value of resourceObj the first time it is set.

Anybody have a potential solution for this?

david_SD

Posts: 4
Joined: Thu Sep 11, 2014 9:28 am

Post by david_SD » Thu Sep 11, 2014 10:10 am
For reference, this is what the log looks like
Code: Select all
9/11/14 7:41:48 AM            INFO      Executing module 'Main'
9/11/14 7:41:48 AM            INFO      Executing task 'readExcel 2.0 (read Config)'
9/11/14 7:41:50 AM            INFO      Data parsed successfully and the rowset variable 'archivalConfig' was created
9/11/14 7:41:50 AM            INFO      Finished task 'readExcel 2.0 (read Config)'
9/11/14 7:41:50 AM            INFO      Entering loop 'forEachLoop'
9/11/14 7:41:50 AM            INFO      Opening file 'QA-DEV Resources.xls'
9/11/14 7:41:50 AM            INFO      Executing task 'setVariable 2.0'
9/11/14 7:41:50 AM            INFO      Variable 'resourceObj' was created and set to 'MuleD01'.
9/11/14 7:41:50 AM            INFO      Finished task 'setVariable 2.0'
9/11/14 7:41:50 AM            INFO      Executing task 'sftp 1.0 (SFTP Delete)'
9/11/14 7:41:50 AM            INFO      Connecting to 'muled01' at port '22' as user 'mule' 
9/11/14 7:41:50 AM            INFO      Executing sub-task 'delete'
9/11/14 7:41:50 AM            INFO      0 file(s) and 0 directory(s) were deleted successfully
9/11/14 7:41:50 AM            INFO      Finished sub-task 'delete'
9/11/14 7:41:50 AM            INFO      Finished task 'sftp 1.0 (SFTP Delete)'
9/11/14 7:41:50 AM            INFO      Executing task 'setVariable 2.0'
9/11/14 7:41:50 AM            WARN      Variable 'resourceObj' was replaced with 'MuleD02'.
9/11/14 7:41:50 AM            INFO      Finished task 'setVariable 2.0'
9/11/14 7:41:50 AM            INFO      Executing task 'sftp 1.0 (SFTP Delete)'
9/11/14 7:41:50 AM            INFO      Connecting to 'muled01' at port '22' as user 'mule' 
9/11/14 7:41:50 AM            INFO      Executing sub-task 'delete'
9/11/14 7:41:50 AM            INFO      0 file(s) and 0 directory(s) were deleted successfully
9/11/14 7:41:50 AM            INFO      Finished sub-task 'delete'
9/11/14 7:41:50 AM            INFO      Finished task 'sftp 1.0 (SFTP Delete)'
9/11/14 7:41:50 AM            INFO      Executing task 'setVariable 2.0'
9/11/14 7:41:50 AM            WARN      Variable 'resourceObj' was replaced with 'MuleQ01'.
9/11/14 7:41:50 AM            INFO      Finished task 'setVariable 2.0'
9/11/14 7:41:50 AM            INFO      Executing task 'sftp 1.0 (SFTP Delete)'
9/11/14 7:41:50 AM            INFO      Connecting to 'muled01' at port '22' as user 'mule' 
9/11/14 7:41:51 AM            INFO      Executing sub-task 'delete'
9/11/14 7:41:51 AM            INFO      0 file(s) and 0 directory(s) were deleted successfully
9/11/14 7:41:51 AM            INFO      Finished sub-task 'delete'
9/11/14 7:41:51 AM            INFO      Finished task 'sftp 1.0 (SFTP Delete)'

I have verified also that the resources (MuleD02, MuleQ01) are actually defined correctly, pointing to different servers, so it shouldn't be connecting to muled01 each time.

Support_Rick

Support Specialist
Posts: 592
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Thu Sep 11, 2014 10:28 am
David,

This is a known situation .. but, is acting as designed.

GoAnywhere Director interprets the variable on the first pass for task evaluation. Thus, the reason you're seeing the first time through work as needed.

The 2nd+ times through, since the original interpretation of the task has been done, it uses what it has been interpreted to do... in this case, the value used during the 1st pass.

To rectify this situation, create a "utility" project to call from within your main loop to do the SFTP task for you. That way, each time you go through the Main loop, it will call the Utility and interpret the utility each time through (as each time it is executed, it is interpreted with the parameters passed into it).

So, in this instance, you would do something like:
Code: Select all
ForEach {myList}
  CallProject SFTPDelete
    Parm ResourceID = ${currArchivalObject["SRC_RESOURCE"]}
    Parm DirLocation = ${currArchivalObject["SRC_LOCATION"]}
    Parm DateFrom = ${DateFrom}
/ForEach
Project SFTPDelete:
Code: Select all
		<sftp resourceId="${ResourceID}" version="1.0" onError="continue">
			<delete>
				<fileset dir="${DirLocation}">
					<dateFilter>
						<include to="${DateFrom}" />
					</dateFilter>
				</fileset>
			</delete>
		</sftp>
You could also add some error checking routines to this and return whether or not there were errors during the execution of the SFTPDelete call. This could also be extended to pass what type of command you're wanting to execute (Put/Get/Delete/List, etc...) There are numerous things you could do here. But, most importantly, it will re-interpret each time through and give you the desired flow you are looking for.

Please let me know if you have any other questions.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
3 posts Page 1 of 1