Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…

919 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

20 Experts available now in Live!

Get 1:1 Help Now