Search code examples
webspherewsadmin

wsadmin upload file from local machine to remote


I'm trying to automate process of deployment and I want to upload some files to WAS using wsadmin (jython). My question is if it is possible to upload file from my standalone wsadmin to remote WAS Server. And if so, is it possible to upload file somewhere out of application (fe. /opt/IBM/WebSphere/AppServer/temp)? I don't want to upload it to specific profile, but to server root.

When I'm deploying application it is copying war/ear file to WAS, so is it there some mechani to upload separate file?

many thanks


Solution

  • AntAgent allows you to upload any file, provided that the content of the file can fit in memory:

    https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.javadoc.doc/web/mbeanDocs/AntAgent.html

    In wsadmin you'll need to use invoke_jmx method of AdminControl object.

    from java.lang import String
    import jarray
    
    fileContent = 'hello!'
    antAgent = AdminControl.makeObjectName(AdminControl.queryNames('WebSphere:*,type=AntAgent,process=dmgr'))
    
    str = String(fileContent)
    bytes = str.getBytes()
    
    AdminControl.invoke_jmx(antAgent, 'putScript', [String('hello.txt'),bytes], jarray.array(['java.lang.String', '[B'], String))
    

    Afterwards you'll find 'hello.txt' file in WAS profile's temp directory. You may use relative paths as well.