LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   python script to move files from open suse linux to windows 7 (https://www.linuxquestions.org/questions/general-10/python-script-to-move-files-from-open-suse-linux-to-windows-7-a-4175442100/)

barathan 12-19-2012 01:39 AM

python script to move files from open suse linux to windows 7
 
hello All!

im a real newbie in linux and python. Learning stage. i want to create a python script that will move/push files from my linux pc to windows 7 pc. i will place that script in cron.hourly. how do i do that? i created a script to move files within linux pc's and it worked. but im having a tough time to create a script to move from linux to windows. can anyone please help? below is my script to move files
from linux to linux :

import os
import time
import glob

filePath = "/usr/local/testlogs/parse/*.*" #path of slave tester
serverPath = "/usr/local/testlogs/DB_parse" #path of master tester

try :
files = glob.glob(filePath)
for f in files :
os.system("scp "+f+" root@192.168.10.1:"+serverPath)
time.sleep(1) #delay 1 sec before file gets deleted one by one.
os.remove(f) #copy and delete files to not save up space

except OSError:
print "parse directory is missing!!"

pan64 12-19-2012 03:12 AM

this script uses scp to copy files, therefore you need to install scp on your windows (something like this: http://www.techrepublic.com/blog/itd...-freesshd/3506, or cygwin's sshd)

barathan 12-19-2012 04:14 AM

hi There!
Thanks! now i can scp from my linux pc to my windows pc. but now im facing another problem whereby, whenever i issue below command :

scp filename.txt barathan.rajalingam@10.34.52.58:/C:\...arathan.rajalingam\Desktop

it asks for password. when i key in my password and it says that that permission denied. any idea why?

pan64 12-19-2012 04:52 AM

It depends on several things. For example the users on linux and windows are different (probably), you need to use the user/password of the target system.
The user you entered has really no right to write into that directory. Probably you can check the log file of the sshd (which one have you installed?)
Do not use \ on linux, if you want to enter windows-like path, use double backslashes: c:\\something\\dir\\Desktop. Also use ' to avoid mishandling of your path:
scp filename.txt 'barathan.rajalingam@host:c:\\users\\barathan.rajalingam\\Desktop'
You can also configure passwordless login, just google "passwordless ssh login windows" and follow the steps.


All times are GMT -5. The time now is 06:02 PM.