简体   繁体   中英

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 ?

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.

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()

Server

python -m http.server

this will create a http server on port 8000

client

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM