FTP in ksh script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP in ksh script
# 1  
Old 09-02-2011
FTP in ksh script


I'm trying to get "ftp" commands work inside a function written in ksh script; but it seems to be not working!!

Here's the code:
function chk_ftp_path {
ftp -ivn $IP_ADDR << EOF

When I run the main script (that calls the above function written in another script) then the script hangs after encountering "EOF"!! I don't know why? Please advice.

# 2  
Old 09-02-2011
Comment out all code, and just print $1,2,3,4 and check if the value passed by you to function is properly reflected while calling?

Also, enable debugging using "set -x".
# 3  
Old 09-02-2011
Hi psshah,

I am actually hard-coding those values in function (only for demo purpose I've shown function accepting values). So the values being passed to the function is not a problem. And I've enabled the debugging too....and this is what it displays!!

+ ftp -ivn ip_addr
+ 0<< \EOF
user user_name passwd
cd /remote/path
............-> hangs until I press ^C

don't know what's happening!! Smilie

# 4  
Old 09-02-2011
You said you are calling the script with the function from another script. You should capture what you pass to that script outside of the function, no?
# 5  
Old 01-05-2012
I am also facing the similar problem in a shell script. Does anybody have the answer?
# 6  
Old 01-05-2012
Can we see all the exact script(s) which matches the "set -x" trace.
The trace does not mention a function call.
The trace does not look like it came from "ksh". What Operating System and version is this?

Please check the script for invisible control characters:
sed -n l scriptname

Please check whether "ftp" is aliased.
alias | grep "ftp"

Please also try with verbose enabled:
set -vx

Last edited by methyl; 01-05-2012 at 12:25 PM..
# 7  
Old 01-06-2012
I am running the script on red hat Linux. I am calling the calling in normal shell.
     ftp -nv hostname <<SCRIPT1
            user $user $password
             cd  /location1
             mget *.txt
                  -------> this is where its hanging 
    case return_value in
    0) echo 'successful file transfer' >> $path/return;;
    *) echo 'Error in ftp' >> $path/return;;

when I run the trace, its showing the following statements and i dont see the update to the file $path/return

Connected to Hostname
331 Password required for username.
230 User username logged in.
250 CWD command successful.

Moderator's Comments:
Mod Comment How to use code tags when posting data and code samples.

Last edited by Franklin52; 01-06-2012 at 06:06 PM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Having a hell of atime with KSH -ftp automation

Following this thread: https://www.unix.com/ip-networking/1935-automated-ftp-task.html I have created the following script: #! /bin/ksh HOST=ftp.mywebsite2.com USER=astrocloud PASSWD=8**** exec 4>&1 ftp -nv >&4 2>&4 |& print -p open $HOST print -p user $USER $PASSWD print -p cd... (3 Replies)
Discussion started by: Astrocloud
3 Replies

2. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

3. Shell Programming and Scripting

Problem with embedded FTP command in Ksh - System Cannot find the specified path.

I have the following FTP embedded in a Ksh script on AIX 5.3 ftp -n <<WHATEVER open user hcistats ******* ascii put $thupdatefile put $thcollectfile quit WHATEVER Here is what my script returns: ... (3 Replies)
Discussion started by: troym72
3 Replies

4. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host= /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

5. Shell Programming and Scripting

How do I write a ksh script that will check if all ftp files are received?

I am trying to code a ksh script that will check to see if all 26 incoming ftp files have been received before proceeding to the next function, which is to rename each file. Here is the pseudo-code of what I am trying to do: <<STEP_1>> IF all ALS files have been transmitted then... (2 Replies)
Discussion started by: doug145
2 Replies

6. Shell Programming and Scripting

KSH, FTP running a set number at a time?

At work we have a script that pulls a file from a list of remote sites every 10 min. Currently it only does this ftp one sites at a time and this process takes up to 8 minutes to complete. I want to have this list of 24 sites and be able to run the ftp from up to 2 sites on the list at a time. I... (1 Reply)
Discussion started by: kofs79
1 Replies

7. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

8. Shell Programming and Scripting

KSH n FTP query

Hi, I have this slightly modified FTP code (thanks to this forum) function gather_FTPDate { HOST= USER= PASSWD= exec 4>${TEMP_LOG_FILE} ftp -nv >&4 2>&4 |& echo $? if ] then echo "Unable to connect to FTP server!!!" >> ${LOG_FILE} return 0 fi print -p open... (2 Replies)
Discussion started by: psynaps3
2 Replies

9. Shell Programming and Scripting


I trying to write a ksh script (without the help of the Kermit libraries) which connects to a ftp server and checks if the file "KEI.done" exists. If the file exists it print "files is there" if it doesnt exist it prints "file is not there". (the print statements will later be replaced with code to... (2 Replies)
Discussion started by: mike509123
2 Replies

10. Shell Programming and Scripting

FTP in a KSH script

Hi, I'm writing a script to perform automated ftp's. What I would like to know is if it is possible to examine return codes or trap any error messages from the remote server. eg. if during the ftp session i cd to a different directory on the remote server and the directory does not exist, can... (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question