Solved

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

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


0
Comment
Question by:milindbansode
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

732 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