Solved

help required to ftp my unix files to windows machine

Posted on 2006-06-29
1
616 Views
Last Modified: 2010-04-21
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
Comment
Question by:karunamoorthy
1 Comment
 
LVL 5

Accepted Solution

by:
sriramiyer earned 500 total points
ID: 17008225
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now