Ragini Dahihande
Ragini Dahihande

Reputation: 686

How do I copy files from windows system to any other remote server from python script?

I don't want to use external modules like paramiko or fabric. Is there any python built in module through which we can transfer files from windows. I know for linux scp command is there like this is there any command for windows ?

Upvotes: 2

Views: 7221

Answers (3)

superK
superK

Reputation: 3972

Server

python -m http.server

this will create a http server on port 8000

client

python -c "import urllib; urllib.urlretrieve('http://x.x.x.x:8000/filename', 'filename')"

where x.x.x.x is your server ip, filename is what you want to download

Upvotes: 1

Dulguun
Dulguun

Reputation: 554

Paramiko is stable, simple and supports Linux, OS X and Windows.

You can install via pip:

pip install paramiko

Simple Demo:

import base64
import paramiko
key = paramiko.RSAKey(data=base64.b64decode(b'AAA...'))
client = paramiko.SSHClient()
client.get_host_keys().add('ssh.example.com', 'ssh-rsa', key)
client.connect('ssh.example.com', username='strongbad', password='thecheat')
stdin, stdout, stderr = client.exec_command('ls')
for line in stdout:
    print('... ' + line.strip('\n'))
client.close()

Upvotes: 1

Sudheesh Singanamalla
Sudheesh Singanamalla

Reputation: 2297

Something similar to scp is the Copy-Item cmdlet that's available in Powershell, You could execute powershell and run a Copy-Item command to copy a file from your local windows system to another directory or a remote server directory.

You need to first set the PowerShell for unrestricted access by doing Set-ExecutionPolicy Unrestriced after which you can use the subprocess module of python to make a call to execute the required script.

Maybe this answer is of help to you.

Upvotes: 1

Related Questions