how to copy a file between 2 computers on the network in python
I am trying to move a log file from a computer, where an operation is performed, to another computer, that will get the log file and process it, returning a document with the result of the analysis.
I am using Python for the job, but I am open to other options (I have to run this copy via console on OSX, due the fact that most of my work is done in shell scripting; so cannot use any visual solution; anything that ca开发者_如何学Pythonn be launched via a script would work too); any suggestion is more than welcome since I do not really have a favorite way to do this (just trying the less problematic....I do not need any security encryption since both of the computers are on my internal network, no communication with the outside is performed).
Hope that someone can point me to the right solution, thanks in advance.
I use this all the time at home so I don't have to keep file sharing daemons running constantly:
python -m SimpleHTTPServer
On the client machine, use a browser or wget.
In fact I use it so often I made this script that prints the IP Address also, named serv
. Feel free to hack it into your needs. Just cd to a folder and serv
it.
#!/usr/bin/env python
import subprocess as sub
import BaseHTTPServer
import SimpleHTTPServer as httpd
# override this method to speed up connection
def _bare_address_string(self):
host, port = self.client_address[:2]
return '%s' % host
BaseHTTPServer.BaseHTTPRequestHandler.address_string = _bare_address_string
# get ip address and print
info = sub.Popen('/sbin/ifconfig', stdout=sub.PIPE).communicate()[0]
tokens = []
for line in info.split('\n'):
if 'inet' in line:
if '127.0.0.1' not in line:
tokens = line.split()
print
print ' ', tokens[1].replace(':', ': '), '\n ',
# start server
try:
httpd.test()
except KeyboardInterrupt:
print '\x08\x08Killed'
NFS mount the filesystem, then both systems can access the same files as if they were local. Otherwise you could use sockets.
精彩评论