Introduction¶
The standard Python module multiprocessing
got introduced in Python 2.6 and makes creating simple client/server applications extremely easy.
Here is an example that shows how to read and write local/remote files. Because it allows accessing arbitrary files it is probably a good idea to not use it exactly like this, but rather to extend, or at least adjust the password.
You can download a package with the following three files py_remote_file-20130730-1437.zip .
Example - Using py_remote_file_client.py in Squish test scripts¶
Prerequisites:
Script
py_remote_file_client.py
must reside in test suite directoryScript
py_remote_file_server.py
must running on the remote computer (started like this:python py_remote_file_server.py
function main()
{
var remote_file_name = "C:\\test.txt";
var local_file_name = "C:\\Users\\MyUser\\Desktop\\test.txt_from-remote";
var cmd = 'python "' + squishinfo.testCase + '/../py_remote_file_client.py" '
+ 'get "' + remote_file_name + '" "' + local_file_name + '"';
result = OS.system(cmd);
if (result != 0) {
test.log("An error occurred");
}
var local_file_name = "C:\\Users\\MyUser\\Desktop\\test.txt";
var remote_file_name = "C:\\Users\\AnotherUser\\test.txt";
var cmd = 'python "' + squishinfo.testCase + '/../py_remote_file_client.py" '
+ 'get "' + remote_file_name + '" "' + local_file_name + '"';
result = OS.system(cmd);
if (result != 0) {
test.log("An error occurred");
}
}
Example - Using py_remote_file_client.py without Squish¶
Prerequisites:
- Script
py_remote_file_server.py
must have been started on the remote computer
Executed in cmd.exe
:
C:\Users\MyUser\Desktop> python py_remote_file_client.py get C:\ThatFileOverThere.txt .\ThatFile-from_remote_computer.txt