Script for copying files from windows to UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script for copying files from windows to UNIX
# 8  
Old 07-31-2014
Quote:
Originally Posted by saleheen
Here's an idea. What if I copy the whole project from windows to unix using recursive scp and use a for loop and wild card to match the directory name in both,as you suggested the stripping of part in unix can be done using pwd, rev and awk? Is that possible? I don't wanna go through the list :/ Is it possible to create a for loop that'll make identical tree for both of them in unix?
1) Your windows system doesn't know the UNIX folder names, scp can't tell it.

2) They're not identical. Not even close -- different names, different depths. If they were handmade they might not even be consistent. There might also be inconsistent case between Windows and UNIX since Windows wouldn't care.

3) How badly would a mistake hurt you, if it guessed wrong and copied the wrong files overtop of good ones?

I don't think you can do a good enough "fuzzy" match to really trust here. So, either make them identical, or build a big list of what Windows folders map to what UNIX folders.
This User Gave Thanks to Corona688 For This Post:
# 9  
Old 07-31-2014
If it guessed wrong and copied wrong files, I'm screwed to some to a good extent and the bad part is I wouldn't even know I'm done big time :/
Let me say one more time. In unix I have CH-species/CH3/,CH2/,CH1/, under each of these I may have 5 or 6 VAS directories,(of course there names will be differently numbered)under each of them I have OPT-0 inside which I want my .cell files
In windows I will create similarly CH-species/CH3/,CH2/,CH1/, and here's the problem. Since these folder are generated by material studio, after the VAS..part it includes CASTEP Energy like VAS-S005-001-Ru444 CASTEP Energy/ inside which I have .cell files and also other files which will be just deleted.
So, what if I use the file transfer window, copy the whole CH-scpecies from windows to unix, trip the unix part to VAS(store it inside a variable), do the same for the windows files and then try to match? Is it possible to trim the "CASTEP Energy" part from all the windows VAS..folders in unix?
Thanks a lot!!
# 10  
Old 08-01-2014
Hmmm. Based on that, my very first and very firm suggestion would be:

BACK UP THAT DATA!

The slightest mistake on our part could doom your project.
This User Gave Thanks to Corona688 For This Post:
# 11  
Old 08-01-2014
But how do I remove that CASTEP Energy part? I've checked, if I put both of them in same depth of directory, it's not impossible, but the CASTEP Energy part is bugging me cause since these are from windows it also includes \ instead of spaces between them. So when I tell my for loop to go inside */*/*/*/ in the last step it sees VAS-S001-002-Ru44R\ CASTEP\ Energy/ and it doesn't recognize what to do :/
# 12  
Old 08-01-2014
If I understand your problem correctly, and you're willing to use busybox and pscp...

On the Windows side, I made example data like:

Code:
C:\Documents and Settings\User>mkdir cp-test
C:\Documents and Settings\User>cd cp-test
C:\Documents and Settings\User\cp-test>mkdir "a CASTEP Energy"
C:\Documents and Settings\User\cp-test>echo a > "a CASTEP Energy"\a.cell
C:\Documents and Settings\User\cp-test>mkdir "b CASTEP Energy"
C:\Documents and Settings\User\cp-test>echo b > "b CASTEP Energy"\b.cell
C:\Documents and Settings\User\cp-test>mkdir "c CASTEP Energy"
C:\Documents and Settings\User\cp-test>echo c > "c CASTEP Energy"\c.cell
C:\Documents and Settings\User\cp-test>mkdir "d CASTEP Energy"
C:\Documents and Settings\User\cp-test>echo d > "d CASTEP Energy"\d.cell

On the UNIX side I made destination folders like:
mkdir -p cp-test/a/OPT-0 cp-test/b/OPT-0 cp-test/c/OPT-0 cp-test/d/OPT-0

Then I created this file as "cp-test.sh":

Code:
#!/bin/sh

WIN='C:/Documents and Settings/User/cp-test'
UNIX='/home/user/cp-test'
UNXUSER="tyler"
UNXHOST="unixhostnameorip"

find "$WIN" -type d -name '*CASTEP Energy' | while IFS="" read -r IPATH
do
	# Convert a/b/c/d into d
	BASE="${IPATH##*/}"
	# Convert 'xxx CASTEP Energy' into 'xxx'
	UNXNAME="${BASE/ CASTEP Energy/}"
	# If that couldn't be stripped, skip this folder
	if [ "$UNXNAME" = "$BASE" ]
	then
		echo "Couldn't strip CASTEP Energy from $BASE"
		continue
	fi
	
        # Remove the echo once you're sure it does what you want
	echo ./pscp.exe -batch -agent "$IPATH"/*.cell	\
		"$UNXUSER"@"$UNXHOST":"$UNIX/$UNXNAME/OPT-0"
done

...and ran it, with busybox and pscp in the same folder, like busybox sh cp-test.sh:

Code:
C:\Documents and Settings\User\cp-test>busybox sh cp-test.sh

./pscp.exe -batch -agent C:/Documents and Settings/User/cp-test/a CASTEP Energy/a.cell user@unixhostnameorip:/home/user/cp-test/a/OPT-0
./pscp.exe -batch -agent C:/Documents and Settings/User/cp-test/b CASTEP Energy/b.cell user@unixhostnameorip:/home/user/cp-test/b/OPT-0
./pscp.exe -batch -agent C:/Documents and Settings/User/cp-test/c CASTEP Energy/c.cell user@unixhostnameorip:/home/user/cp-test/c/OPT-0
./pscp.exe -batch -agent C:/Documents and Settings/User/cp-test/d CASTEP Energy/d.cell user@unixhostnameorip:/home/user/cp-test/d/OPT-0

C:\Documents and Settings\User\cp-test>

If I remove the echo, and have pageant running with an available key, it does this:

Code:
C:\Documents and Settings\User\cp-test>busybox sh cp-test.sh
a.cell                    | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%
b.cell                    | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%
c.cell                    | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%
d.cell                    | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%

C:\Documents and Settings\User\cp-test>

...and on the UNIX side, the files have appeared:

Code:
$ find cp-test -name '*.cell'

cp-test/c/OPT-0/c.cell
cp-test/d/OPT-0/d.cell
cp-test/a/OPT-0/a.cell
cp-test/b/OPT-0/b.cell

$

This User Gave Thanks to Corona688 For This Post:
# 13  
Old 08-01-2014
wow! awesome! let me understand and try this thing, I have never used busybox or pscp before though. Thanks a lot Corona688!! Smilie
# 14  
Old 08-06-2014
busybox is an entire UNIX "toolkit" in a single executable, bringing a shell and lots of standard commands. They use it in things like wireless routers where space is limited. Or when you want to write a shell script on Windows without installing 900mb of Cygwin things.
This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying the files to Windows server from UNIX server

Hi Team, I had a requirement to write a shell script which automatically transfer the files from unix server to windows server. I can able to unix to unix using Scp command. I am not sure how to do unix to windows. I am very new on this concept. Could you please help me or guide in... (4 Replies)
Discussion started by: gvkumar25
4 Replies

2. Shell Programming and Scripting

Problem copying files from windows to unix

Hello, I want some directions for a command inside a shell script which would copy files from some path on my windows os (say my documents) to the path where my shell script is saved and I want it to exit the sftp session and continue executing the remaining lines in my shell script after... (2 Replies)
Discussion started by: Vishwa308
2 Replies

3. Shell Programming and Scripting

Unix shell script to Copy files from one Windows server to another Windows server.

Can anybody please help me on how to code for the below requirement: I need to write a shell script (on different unix server) to copy files from multiple folders (ex. BRN-000001) from one windows server (\\boldls-mwe-dev4)to a different windows server(\\rrwin-ewhd04.ecomad.int). This shell... (4 Replies)
Discussion started by: SravsJaya
4 Replies

4. Shell Programming and Scripting

RCP for copying the files from one drive to other on Windows

Hi, I have a requirement to move the files between two drives in windows machine from Korn sheel. I came to know that It can be done through RCP. Can any one help me with syntax for connecting to Windows machine and moving the files with RCP in KSH? Thanks in advance. Double post.... (0 Replies)
Discussion started by: Raamc
0 Replies

5. Shell Programming and Scripting

Error copying files from Unix (Solaris10) to Windows Server 2003 using scp/sftp

Hi, I have generated a Public/Private Key Pair in Solaris Unix (source) server and deployed the Public key in Windows 2003(target) server .ssh directory of user profile. When i try to connect(ssh, scp, sftp) from Unix, i'm getting below error message. Sun_SSH_1.1, SSH protocols 1.5/2.0,... (0 Replies)
Discussion started by: ajaykumarb
0 Replies

6. UNIX for Dummies Questions & Answers

copying files from Windows!!

All, I have a requirement where Iwill be getting the CSV files on windows Shared Drive, and I need to copy those to my unix directory... Is there anyway we can do this?? Thanks, freakabhi (4 Replies)
Discussion started by: freakabhi
4 Replies

7. Shell Programming and Scripting

copying files from UNIX to windows using FTP

Hi, I want to transfer the approx 10k files available on UNIX Server to Windows Server using FTP Command. is it possible? how ? Thanks in advance. Sachin. (1 Reply)
Discussion started by: ssachins
1 Replies

8. Shell Programming and Scripting

writing script in UNIX for copying files in two server

can anyone help me in writing script in UNIX for copying files in two server from the third server after checking the files in the third server and if there is anything new in the third server automatically it should be added to the rest of the two servers and if same file is existing in the two... (4 Replies)
Discussion started by: REKHA09
4 Replies

9. Shell Programming and Scripting

copying from unix to windows

Hi, I am new to shell scripting, I want to copy some imp files from solaris server to windows server in a particular directory,username and password should be inside script and i want to it should copy output of some commands to windows server.first it will copy output of command to file then... (1 Reply)
Discussion started by: manoj.solaris
1 Replies

10. UNIX for Dummies Questions & Answers

Copying file from Unix workspace to Windows Network

Hi All, I am new for Unix, and facing one problem I wanted to copy some of files from my Unix workarea to Window network drive. I am not able to use copy or move command for this, as this only works within workarea. Please let me know, how it can be done. (2 Replies)
Discussion started by: ashwanis
2 Replies
Login or Register to Ask a Question