Solved

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

Posted on 2011-03-16
3
1,792 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

"The time has come," the Walrus said, "To talk of many things: Of sets--and lists--and dictionaries-- Of variable kinks-- And why you see it changing not-- And why so strange are strings." This part describes how variables and references (see …
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

813 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

10 Experts available now in Live!

Get 1:1 Help Now