Solved

How to copy files from windows machine to linux server in Python?

Posted on 2011-03-16
3
1,643 Views
Last Modified: 2012-05-11
How to copy files from windows machine to linux server in Python?


0
Comment
Question by:milindbansode
3 Comments
 
LVL 17

Expert Comment

by:sgsm81
ID: 35146650
0
 
LVL 5

Assisted Solution

by:vks_vicky
vks_vicky earned 200 total points
ID: 35146663
1. First mount your Windows server on linux (Samba share)

2. And then implement a normal copy program in Python to copy.
0
 
LVL 8

Accepted Solution

by:
LunarNRG earned 300 total points
ID: 35148929
You can use ssh/scp to copy files from windows to a linux server. There are several ssh implementations in python, some rather old and possibly unmaintained ... for example, paramiko[1], pyssh[2], and twisted-conch[3]. But you can also just wrap a system call to your favorite windows scp client[4]. Something like (completely untested),

#!/usr/bin/env python
from subprocess import Popen, PIPE, STDOUT

# you must pre-configure putty/pscp to use pub key auth
def remote_copy(server, user, src, dst):
    p = Popen(
        'pscp.exe -batch %(src)s %(user)s@%(server)s:%(dst)s' % locals(), 
        shell=True, stdout=PIPE, stderr=STDOUT
    )
    all_output, null = p.communicate()
    return all_output

Open in new window


[1] http://www.lag.net/paramiko/
[2] http://pyssh.sourceforge.net/
[3] http://twistedmatrix.com/documents/current/conch/howto/conch_client.html
[4] http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html#pscp
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now