FTP from Windows to UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP from Windows to UNIX
# 1  
Old 07-20-2009
FTP from Windows to UNIX

will this work, knowing that the file is in a directory in windows.. It is
going from a drirectory in windoxs to UNIX \

Code:
# Error Handling Function
function ErrorHandle
{ 
     # if type is 1, then the file does not exist or unreadable
     if [ $type -eq 1 ]
     then
          echo "File "$UpLoadFileName" does not exist or unreadable" >> $LogFile;
          echo "Subject: Error in Running Script\n Error in uploading file script "$ScriptName". File "$UpLoadFileName" does not exist or unreadable" > EmailMessage;
          sendmail -F " File Upload" $EmailAddress < EmailMessage;
          rm EmailMessage;
     fi
     # if type is 2, then the file has zero size
     if [ $type -eq 2 ]
     then
          echo "File "$UpLoadFileName" has a zero size value" >>$LogFile;
          echo " Subject: Error in Running Script\n Error in uploading file script "$ScriptName". File "$UpLoadFileName" has a zero size value" > EmailMessage;
          sendmail -F "The eluppdtop.dat File Upload" $EmailAddress < EmailMessage;
          rm EmailMessage;
     fi

Image

Last edited by zaxxon; 07-20-2009 at 08:49 AM.. Reason: code tags
# 2  
Old 07-20-2009
Use CODE-tags when posting code, data or logs to enhance readability and preserve formatting like indention etc., ty.

Make clear what you intend to do. You mention FTP in the subject but then there is nothing about FTP in the script. Also it is not clear if you want to check something remote or locally and where this will run, in cygwin environment for example on windows side or on the unix side. Be more precise and clear.

Also there is missing a curled bracket to close the function.

The other thing is, why you just don't try it out?!
# 3  
Old 07-20-2009
Here is the full script, this is going to run in UNIX
THE FILE is in WINDOWS
The file is in a directory in WINDOWS
LocalDir='cd orgs /"Financial Aid"/"MIIS"/"0910"/"FTP" ';
and I wanted to move it to
="/u02/sct/banjobs/
the XXXX I changed, I don't want this all over the internet

I am getting this error
miis_ftp.ELM_SUP.shl[34]: eluppdtop.dat: not found
miis_ftp.ELM_SUP.shl[45]: /u02/sct/banjobs: cannot execute
miis_ftp.ELM_SUP.shl[87]: cd: bad argument count


Code:
"miis_ftp.ELM_SUP.shl" 133 lines, 3606 characters 
#**************************************************************************
# Script:  miis_ftp.ELM_SUP.shl
#
# Author:   
# Date:    07/15/2009
#
# Purpose:
# This script initiates an FTP to transfer files are downloaded from ELM,named #  xxxxxx00.SUP to \u02\sct\dataload\finaid,
#
#
# Directory Location for script:
#       Script object locations is -- Database Home Dir/middlebury/shl
#
# Audit Trail:
# 07/16/2009   Change remote host & user/password for new DFS folder system.
#                         Set change directory command for new folder path.
#                         Change MPATH from hard-coded value to $BANNER_HOME
#                         Include header info
#
#**************************************************************************

MPATH=$BANNER_HOME;

JOBNUM=$ONE_UP;
USER=$BANUID;

LPATH="/u02/sct/banjobs/";



ScriptName="miis_ftp.ELM_SUP.shl";
UpLoadFileName=`date "+%m%d%y"00.SUP`;
NewName= "eluppdtop.dat" ;

LocalDir='cd orgs /"Financial Aid"/"MIIS"/"0910"/"FTP" ';
CopyLocalDir='cd orgs /"Financial Aid"/"MIIS"/"0910"/"FTP" ';


RemoteHost="middfiles.middlebury.edu";
### look at this
RemoteUser="xxxxxxx";
RemotePass="xxxxx";

CDRemoteDir= "/u02/sct/banjobs";

TMode="ascii"; # Transfer mode
EmailAddress="xxxxxx@xxxxx.edu";
LogFileName="miis_ftp.ELM_SUP_${USER}_${JOBNUM}.log";
LogFile="${LPATH}${LogFileName}";

TodayDate=`date`;

echo "\nActivities for "$TodayDate":" >> $LogFile;
#========================================================================#

# Error Handling Function
function ErrorHandle
{
# if type is 1, then the file does not exist or unreadable
if [ $type -eq 1 ]
then
echo "File "$UpLoadFileName" does not exist or unreadable" >> $LogFile;
echo "Subject: Error in Running Script\n Error in uploading file script "$ScriptName".  File "$UpLoadFileName" does not exist or unreadable" > EmailMessage;
sendmail -F "  File Upload" $EmailAddress < EmailMessage;
rm EmailMessage;
fi

# if type is 2, then the file has zero size
if [ $type -eq 2 ]
then
echo "File "$UpLoadFileName" has a zero size value" >>$LogFile;
echo " Subject: Error in Running Script\n Error in uploading file script "$ScriptName".  File "$UpLoadFileName" has a zero size value" > EmailMessage;
sendmail -F "The eluppdtop.dat  File Upload" $EmailAddress < EmailMessage;
rm EmailMessage;
fi

echo "End of activities\n" >> $LogFile

# Exit the program since error occurred
exit 1;

}

#========================================================================#
# Change the directory to one contains the file to be transported
cd $LocalDir;

# Do an -r command on the desired file ensure that the file exist and readable
if [ ! -r $UpLoadFileName ]
then
        type="1";
        ErrorHandle;
fi

# Do an -s command on the desired file ensure that the file exist
# and is not null
if [ ! -s $UpLoadFileName ]
then
        type="2";
        ErrorHandle;
fi


#========================================================================#
# Initiate the FTP process

# Loop through remaining parameters to create ftp commands.
(

# Enter user-name and password in host machine
echo "user $RemoteUser $RemotePass"

# Set transfer mode
echo $TMode

# Change directory in host machine
echo ${CDRemoteDir}

# Change local directory in local machine
echo lcd $LocalDir

# Transfer original file name
echo put $UpLoadFileName

# End ftp session
echo quit

) | ftp -vin $RemoteHost >> $LogFile

# End of FTP Process
#========================================================================#


Last edited by DukeNuke2; 07-20-2009 at 09:21 AM.. Reason: corrected code tags
# 4  
Old 07-20-2009
You have to use code tags. Seriously.
You don't have to use ; after every line if there is no command after.
In line 32 variable is defined incorrectly: remove extra space after "="!

I think (sorry) that script is poorly written with minimal BASH knowledge.

Cheers
Chris

Last edited by columb; 07-20-2009 at 11:00 AM..
# 5  
Old 07-21-2009
To debug your script, turn debugging inside it with
Code:
set -x

on, and with
Code:
set +x

you can turn it off. So you will see the current values of your variables etc. while the script is being processed.

Good luck.
# 6  
Old 07-22-2009
I still having problems with this
I am getting this error, I ask my DBA he gave me acceess to th folder, I don't get it

echo cd orgs/"Financial Aid"/"MIIS"/"0910"/"FTP"
+ echo lcd /u02/sct/dataload/finaid
+ echo put 07210900.SUP
+ echo quit
+ 1>> /u02/sct/banjobs/miis_ftp.ELM_SUP__.log
07210900.SUP: No such file or directory
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FTP from windows to unix server using unix shell script

Hi, Is it possible to ftp a huge zip file from windows to unix server using unix shell scripting? If so what command i need to use. thanks in advance. (1 Reply)
Discussion started by: Shri123
1 Replies

2. Shell Programming and Scripting

UNIX script to FTP file from UNIX server to windows

Hi, I am new to this subject.....Can someone please help me out with the script... unix usernm "sdhftst" unix pwd "chsd13" windows usernm "dfghtst" windows pwd "chsd13" path..../xxx/xxxxx/xxxxxx/xxxxxxx please can u get me a script...its only one file to get ftp. Thanks... (2 Replies)
Discussion started by: himakiran9
2 Replies

3. AIX

Do I need to configure my local windows to FTP files from local windows to a UNIX AIX server?

Hi Friends, I have this script for ftping files from AIX server to local windows xp. #!/bin/sh HOST='localsystem.net' USER='myid_onlocal' PASSWD='mypwd_onlocal' FILE='file.txt' ##This is a file on server(AIX) ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD put $FILE... (1 Reply)
Discussion started by: rajsharma
1 Replies

4. Windows & DOS: Issues & Discussions

UNIX to WINDOWS FTP

Hi gurus, I need to FTP files from a UNIX box to a WINDOWS server. FTP is running on the WINDOWS server. I am able to log in to the WINDOWS machine with FTP, however when i do a dir in the ftp prompt i get the following 200 PORT command successful. 150 Opening ASCII mode data connection for... (3 Replies)
Discussion started by: ladarlsan
3 Replies

5. Shell Programming and Scripting

ftp from windows to unix using a perl script on unix machine

i need to ftp a file from windows to a unix machine by executing a sript(perl/shell/php) from that unix machine.i can also use HTML and javascript to build forms. (3 Replies)
Discussion started by: raksha.s
3 Replies

6. Shell Programming and Scripting

ftp from unix to windows

How to do ftp from unix to windows i have some files in a dir in unix box and i want to put those files in windows through FTP. How to do this ? (9 Replies)
Discussion started by: ali560045
9 Replies

7. UNIX for Dummies Questions & Answers

Windows to UNIX FTP

Good Morning, I am currently having a setup of running a batch file in windows to ftp certain files to unix and after that one i login to a unix box to manually run a script to clean up those files and combine them into one and get go back to windows to run another batch of file to get the... (4 Replies)
Discussion started by: ryan_estiya
4 Replies

8. UNIX for Dummies Questions & Answers

FTP from unix to Windows

Hi, I know that there should be a FTP server in Windows or a FTP listener daemon running in windows. Iam a beginner. May I know, what setup need to be done on Windows/unix end so that, a file can be transferred using sftp/scp from unix to windows. Thanks in Advance. (2 Replies)
Discussion started by: deepakwins
2 Replies

9. UNIX for Dummies Questions & Answers

FTP from windows to unix

Hi all, How to FTP an excel format file located in windows to unix using shell script.Any particular commands we have to use? Thanks& Regards, rrs (4 Replies)
Discussion started by: rrs
4 Replies

10. UNIX for Dummies Questions & Answers

ftp from unix to windows

Hi, I have been using ftp to transfer files back and forth between windows and unix machines. But everytime i started the ftp session from the windows machine. I have a question why I am not able to connect to the same windows machine from the same unix machine. How do I do this? ... (11 Replies)
Discussion started by: oldtrash
11 Replies
Login or Register to Ask a Question