How to copy a file on remote machine using PySTAF

476 Views Asked by At

Considering the following:

from PySTAF import *
import sys


try:
    handle = STAFHandle("MyTest")
    request = 'COPY FILE "C:\Users\NET\2.jpg" TOFILE "C:\aa.jpg" TOMACHINE 192.168.1.139'
    result = handle.submit('192.168.1.139', 'FS', request)


except STAFException, e:
    print "Error registering with STAF, RC: %d" % e.rc

I can't find the way to copy the jpg file ("2.jpg") on the remote machine (192.168.1.139). From CMD I use the following:

STAF local FS COPY FILE "C:\Users\NET\2.jpg" TOFILE "C:\aa.jpg" TOMACHINE 192.168.1.139

and it's working but nothing happens when I run the script. The file is not copied on the remote machine. No errors are thrown. I use:

request = 'START SHELL COMMAND "net start Themes" wait returnstdout'
result = handle.submit('192.168.1.139', 'PROCESS', request)

to start a windows service and it's working.

1

There are 1 best solutions below

0
On BEST ANSWER

This should work to COPY to C:\Temp dir of remote:

from PySTAF import * 

filename = 'C:\\Users\\NET\\2.png'
destination = '192.168.1.139'
copy_cmd =  "COPY FILE {} TODIRECTORY c:\Temp TOMACHINE {}".format(STAFWrapData(filename),STAFWrapData(destination))
result = handle.submit("local", "FS",copy_cmd)
print result.result
assert result.rc == STAFResult.Ok

result.result will print the error in case there is any.