How to read and write file from remote server using python

Spread the love

Introduction to Remote Server in python :
The standard Python module multiprocessing got introduced in Python 2.6 and makes creating simple client and server applications in extremely easy way.

In this article we will learn how to read and write local/remote files.

But why ?

Reason is it allows accessing arbitrary file it is probably a good idea to not use it exactly like this, but rather to extend, or at least adjust the password.
For Example –
Method 01) Using py_remote_file_client.py in Squish test scripts

Prerequisites:

Script py_remote_file_client.py must reside in test suite directory

Script 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 02 –

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

Summary :

In this article we saw How to read a file from remote server using python so about this article you have any query then free to ask me.

I am Mr. Sachin pagar Embedded system engineer, the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

sachin Pagar

I am Mr. Sachin pagar Embedded system engineer, the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply