Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there any way to automate the process of copying the files between windows and unix without doing it manually, using tools such as winscp.

I need to copy files from unix to windows such by executing some commands in windows. I goolged it and found these tools that can do this.

ftp
sftp
scp
pscp
winscp console.

EDIT : Can I get something using pscp because I just found out that ftp is not enable in my servers.

Please suggest a way of doing it and I need to run whatever script/command in windows only for copying the unix files.

EDIT 2 : Getting this error in winscp console for sftp :

winscp> get abc.sh c:\
abc.sh                    |          0 KiB |    0.0 KiB/s | binary |   0%
Can't create file 'c:\abc.sh'.
System Error.  Code: 2.
The system cannot find the file specified
(A)bort, (R)etry, (S)kip, Ski(p) all:
share|improve this question
    
Regarding your edit 2: You may not have permission to create C:\abc.sh on windows. –  Bonsi Scott Jan 24 '13 at 17:10

5 Answers 5

up vote 2 down vote accepted

I would use WinSCP script for this Here you have some good piece of documentation on how to do this. Example script :

# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
# open sftp://user:password@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Connect
open sftp://user@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Change remote directory
cd /home/user
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
get examplefile.txt d:\
# Disconnect
close
# Connect as a different user
open user2@example.com
# Change the remote directory
cd /home/user2
# Upload the file to current working directory
put d:\examplefile.txt 
# Disconnect
close
# Exit WinSCP
exit

Then save it to example.txt and use this command :

winscp.exe /console /script=example.txt

share|improve this answer
    
+1thanks, i will try this one also –  munish Jan 24 '13 at 11:09

You say you want to automate the process but the at the same time you say you want to run some commands. Other answers contain some command but if you want to have automation, checking out unison might be worth a try. It allows not only unidirectional syncing but also provides a way to keep 2 directories in sync on different machines.

share|improve this answer

There are several solutions... One way impacts how you'll approach it is where it should be initiated from.

From the Unix device, you should be able to mount a Windows file share and handle it like keeping local files synchronized. (Filenames with characters that Windows dislike might complicate it...)

You can also share the drive and mount it using NFS on Windows (It is in Services for Unix on XP, and an optional component in Vista and newer (might need specific editions, some alternatives are also available)). (Samba can also be used for a Windows file share if you do not want to install the NFS client on Windows)

Once that is set up, you can use tools like Unison and Rsync (or cp for simple cases) (if you do it from the Unix side) or SyncToy or similar tools (for the Windows side) as you would for local files.

scp (and the PuTTY-bundled equivalent pscp might be easier to secure, but need SSH keys set up to work automatically). curl also supports SCP and SFTP (mainly for fetching files) and might be useful for several other options as well.

share|improve this answer

You should consider also rsync. There are many windows ports.

http://en.wikipedia.org/wiki/Rsync

share|improve this answer

You can use Samba as file sharing.When you setup it, you can automate it via shell script and crontab.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.