Solved

Issue with ftp shell script

Posted on 2011-09-14
7
437 Views
Last Modified: 2012-06-27
I'm trying to set up a shell script that will ftp a file from another server. Here is the code I have currently:

 
#!/usr/bin/ksh

HOST=testdataload
USER=ollie
PASSWD=*********

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd /home/ollie/scripts/backup 
print -p binary
#print -p hash
print -p prompt
print -p lcd /home/opike/scripts/backup
print -p mget *.gz
print -p bye

wait
exit 0

Open in new window


This script works some of the time and fails at other times. When it fails, it returns the following output:
Connected to testdataload.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
331 Please specify the password.
230 Login successful.
250 Directory successfully changed.
200 Switching to Binary mode.
Interactive mode off.
Local directory now /home/opike/scripts/backup
221 Goodbye.

The mget *.gz command is just skipped over without any error message being displayed.

When I interactively run the ftp command line client and enter the commands one by one, it always works... and that seems to "unclog" something because right after that I will go back and run the script, and bingo, it works again. But then a few hours later it starts failing again....

This is on CentOS 5.2 btw.
0
Comment
Question by:opike
7 Comments
 
LVL 1

Accepted Solution

by:
dalewalker111 earned 500 total points
ID: 36541187
Do you have lftp on the system? While this isn't a ksh solution, I've found this has helped me in the past:
 
#!/bin/sh
HOST=testdataload
USER=ollie
PASSWD=*********

lftp -u ${USER},${PASSWD} ${HOST} <<EoF
cd /home/ollie/scripts/backup
lcd /home/opike/scripts/backup
binary
prompt
mget *.gz
bye
EoF

Open in new window

0
 
LVL 4

Expert Comment

by:rbride
ID: 36541784
@dalewalker111 writes the ftp commands using the HERE document. This ensures that the commands are not executed until the login process is finished, so my suggestion is, even if you don't have lftp, to rewrite your script to be similar to dalewalker111's.
0
 

Author Comment

by:opike
ID: 36543124
@rbride - Not sure what you mean by the "HERE document".
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 7

Expert Comment

by:jackiechen858
ID: 36545701
print -p mget *.gz


Will there always be a .gz file?

My guess is when you run the script, sometime the gz file is not there yet; so it directly return.


0
 

Author Comment

by:opike
ID: 36585183
@jackiechechen858:

I've verified that the .gz file is there. Plus, without changing anything on the server side, if I manually ftp from the client and enter in the commands by hand, it works.
0
 
LVL 4

Expert Comment

by:rbride
ID: 36585372
@opike
The HERE document is where you get the input from the script inline.

You wrote in one part <<EOF
...stuff
<<EOF

well that's an example of using the HERE document.
See for example: http://tldp.org/LDP/abs/html/here-docs.html
0
 

Author Closing Comment

by:opike
ID: 36594262
Your script works great. Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fixing Non-Standard characters in text 8 90
Remove a folder in Linux 9 90
Linux Copy Command - All Files inc Directory 1 23
Looking for open port with Telnet 5 12
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Hello to you all, I hear of many people congratulate AWS (Amazon Web Services) on how easy it is to spin up and create new EC2 (Elastic Compute Cloud) instances, but then fail and struggle to connect to them using simple tools such as SSH (Secure…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…

919 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

20 Experts available now in Live!

Get 1:1 Help Now