• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 648
  • Last Modified:

help required to ftp my unix files to windows machine

I am woking in both the UNIX and Windows environments.
I need to ftp files quite often from UNIX to WINSOWS and vice versa.

I need a script to automate the process using a UNIX shell script so that the files should go to Windows machine automatically.

like in shell prompt
myftp *.TXT
myftp *.CBL
...
...
etc.

This is needed urgently.

I am a novice user in UNIX.

0
karunamoorthy
Asked:
karunamoorthy
1 Solution
 
sriramiyerCommented:
Hello Karunamoorthy,

The following scripts may used for transferring files from UNIX to WINDOWS and from WINDOWS to UNIX
Here you have to replace the actual ip address of your unix machine.
and in cd the command you have to replace your windows virtual FTP directory name with the path.

and using a .netrc file. The ftp man page documents the format of .netrc. To accomplish the task of using ftp in a shell script you would have to fill out a .netrc file something like this:

machine something.else.com
login myid
password mypassword

and

ftp demands that .netrc not have group or world read or write permissions i.e.
PS the rights on .netrc MUST be 0600 and it must be owned by the user running the FTP command and exist in their home directory


script 1: UNIX TO WINDOWS
-------------------------
ls $* > ftp.lst
while read infile
do
ftp -v 80.0.0.15 >ftp.work 2>ftp.err <<!
cd winftpdirname/foldername  
put $infile
bye
!
grep "226" ftp.work|awk -v fname="$infile" '{ print "File : ",fname,$2,$3}' |tee $$
[ ! -s $$ ] && cat ftp.err && rm ftp.work ftp.err $$ && exit 1 || rm ftp.work ftp.err $$
done < ftp.lst
echo "\nTotal Files transfered = `wc ftp.lst| awk '{print $1}'` "

rm ftp.lst

script 2: WINDOWS TO UNIX
-------------------------
ftp -v 80.0.0.15  > ftp.worked 2> ftp.failed <<!
ascii    
cd winftpdirname/foldername
get $1  
bye
!

grep "226" ftp.worked|awk -v fname=$1 '{print "File : ",fname,$2,$3}'|tee $$

[ ! -s $$ ] && cat ftp.failed && echo "error ..." && rm ftp.worked ftp.failed $$ && exit 1 || rm ftp.worked ftp.failed $$

from
SriRamIyer.


0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now