Follow Us on Twitter

Creating FTP connection factories using WLST

by Mike Heeren on June 29, 2016 · 0 comments

Creating FTP connection factories using the Weblogic console can take a lot of time, mainly because it are multiple screens you have to click through every time. But creating these FTP connection factories can be done a lot easier and faster when using a WLST script.

The following script can be used as a base for your script to generate your FTP connection factories. I have used this script on a Weblogic 12c environment.

# Script settings
appName = 'FtpAdapter'

moduleOverrideName = appName + '.rar'
moduleDescriptorName = 'META-INF/weblogic-ra.xml'

soaHome = '/u01/Oracle/Products/Middleware/soa'
appPath = soaHome + '/soa/connectors/' + moduleOverrideName
planPath = soaHome + '/soa/FTPAdapterPlan.xml'

# Connect to Weblogic server
print('Connecting to local weblogic domain... ')
username = raw_input('Enter username: ')
password = raw_input('Enter password: ')

# Method to insert variable to deployment plan
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
        while wlstPlan.getVariableAssignment(name, moduleOverrideName, moduleDescriptorName):
            wlstPlan.destroyVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
        variableAssignment = wlstPlan.createVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
        wlstPlan.createVariable(name, value)
        print 'Error during makeDeploymentPlanVariable: ', sys.exc_info()[0]

# Update property for FTP adapter
def updatePropertyForFtpAdapter(deploymentPlan, jndiName, propertyName, propertyValue):
        shortJndiName = jndiName.split('/')[2]
        makeDeploymentPlanVariable(deploymentPlan, 'ConfigProperty_' + propertyName + '_Value_' + shortJndiName, propertyValue, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="' + jndiName + '"]/connection-properties/properties/property/[name="' + propertyName + '"]/value', moduleOverrideName)
        print 'Error during updatePropertyForFtpAdapter: ', sys_exc_info()[0]

# Method to create new FTP connection factory
def createFTPConnectionFactory(jndiName, type, host, port, securePort, username, password, walletLocation='', walletPassword=''):
        newPlan = loadApplication(appPath, planPath)
        makeDeploymentPlanVariable(newPlan, 'ConnectionInstance_' + jndiName + '_JNDIName', jndiName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="' + jndiName + '"]/jndi-name', moduleOverrideName)
        if(type == 'sftp'):
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseFtps', 'false')
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseSftp', 'true')
        elif(type == 'ftps'):
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseFtps', 'true')
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseSftp', 'false')
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseFtps', 'false')
            updatePropertyForFtpAdapter(newPlan, jndiName, 'UseSftp', 'false')
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Host', host)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Username', username)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Password', password)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'Port', port)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'SecurePort', securePort)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'WalletLocation', walletLocation)
        updatePropertyForFtpAdapter(newPlan, jndiName, 'WalletPassword', walletPassword)
        print 'Error during createFTPConnectionFactory: ', sys.exc_info()[0]

# Create FTP connection factories
    createFTPConnectionFactory('eis/Ftp/ftp_server1', 'ftp', '', '21', '21', 'username', 'password')
    createFTPConnectionFactory('eis/Ftp/sftp_server1', 'sftp', 'localhost', '22', '22', 'username', 'password')
    createFTPConnectionFactory('eis/Ftp/ftps_server1', 'ftps', 'localhost', '990', '990', 'username', 'password', '/location/to/pkcs/wallet/ftps_wallet.p12', 'wallet_password')
    print 'Updating and restarting application...'
    updateApplication(appName, planPath);
    print 'Done with changes. Calling activate...'
    print 'Unexpected error: ', sys.exc_info()[0]

Save the script as on the Weblogic server and execute the following statement:


At the moment I have only implemented the createFTPConnectionFactory method to be able to configure the Host, Username, Password, Port, SecurePort, WalletLocation and WalletPassword properties. However, if you want to be able to edit other properties via this script, it is very easy as well.

To view all properties of an existing FTP connection factory, open the Weblogic console and navigate to Deployments > FtpAdapter > Configuration > Outbound Connection Pools. Extend javax.resource.cci.ConnectionFactory and select the desired connection factory. You will immediately see 8 pages full of properties. With some minor modifications to the WLST script, it is very easy to edit any of these properties. We just have to add a call to updatePropertyForFtpAdapter within the createFTPConnectionFactory method, and provide the application plan, the JNDI name of the connection factory we want to edit, the property name (as shown in the Weblogic console) and the desired property value.

For example, if we want to use implicit SSL, we can see the property UseImplicitSSL via the Weblogic console, which is false by default. To make this property value true by default, we just have to add the following line before the statement.

updatePropertyForFtpAdapter(newPlan, jndiName, 'UseImplicitSSL', 'true')

I hope this will save you a lot of time when configuring your FTP connection factories. If you have any problem with this script, please let me know.


Oracle SOA Suite 11g – Creating Resource Adapter Connection factories through WLST for Database Adapter,MQ Adapter and FTP Adapter

Creating FTP connection factories using WLST, 4.0 out of 5 based on 1 rating
VN:D [1.9.22_1171]
Rating: 4.0/5 (1 vote cast)
Tags: , , , ,

{ 0 comments… add one now }

Leave a Comment


Previous post:

Next post:

About Whitehorses
Company profile

Whitehorses website

Home page

Follow us
Blog post RSS
Comment RSS