Linux Red Hat - FTP question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux Red Hat - FTP question
# 1  
Old 02-11-2010
Linux Red Hat - FTP question

Hi Everyone,

Based on what I have read so far and what others have posted on this forum, I have come up with the following script to download and upload files from and to a FTP sever:

Code:
HOST=xyz.com
USER=someuser
PASSWD=somepwd

tmpfile=/tmp/files.$$

indir=/tmp/inbound
outdir=/tmp/outbound
inholddir=/tmp/inhold

ls $outdir/*.xml > $tmpfile 2>/dev/null

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

print -p open $HOST
print -p user $USER $PASSWD
print -p ascii
print -p prompt off

if [[ -s $tmpfile ]]
then
  print -p cd Upload
  cat $tmpfile 2>/dev/null | while read xml_file
  do
    print -p put $xml_file
    rm -f $xml_file
  done
  print -p cd ..
fi

print -p cd Download
print -p lcd $inholddir
print -p mget *.xml
ls $inholddir/*.xml > $tmpfile 2>/dev/null
if [[ -s $tmpfile ]]
then 
  cat $tmpfile 2>/dev/null | awk -F "/" '{print $NF}' | while read xml_file
  do
    print -p delete $xml_file
    mv -f $inholddir/$xml_file $indir
  done
fi

rm -f $tmpfile

print -p bye
wait
exit 0

As you can see, after I perform "mget", I am trying to get a list of the XML files that were downloaded so that I can delete them from the remote FTP server and move them to the $indir on the local server. However, the "ls $inholddir/*.xml > $tmpfile 2>/dev/null" command generates no output even though files were sucessfully downloaded and are present in the $inholddir directory. I am not sure why. Can someone point me in the right direction?

Thanks!

PS: The reason I want to get a list of the downloaded files and then delete each file individually is because there is a possibility of new files appearing in the remote "Download" directory while the mget and/or the delete is in process (potential "timing" issue). In such cases, I don't want to delete files that have not been downloaded yet.
# 2  
Old 02-12-2010
for ftp mget to work without a prompt and answer you need: ftp -inv
-i turns off prompting for mput and mget as each file is processed.
# 3  
Old 02-12-2010
Quote:
Originally Posted by jim mcnamara
for ftp mget to work without a prompt and answer you need: ftp -inv
-i turns off prompting for mput and mget as each file is processed.
Well, the issue I am having is not with the prompting but with getting a list of all the XML files after they were downloaded to the local server using mget. So as soon as mget executes to download lets say 10 files in the $inholddir directory on the local server, I am running this command:

ls $inholddir/*.xml > $tmpfile 2>/dev/null

However, $tmpfile contains nothing even though there are files in the $inholddir (that were downloaded from the remote server).

Any ideas as to why this is happening?

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Fedora

Which is the better platform to learn UNIX/Linux (Kali Linux Vs. Red Hat or other)?

I just started a new semester and I started my UNIX class yesterday. I've already decided to use python along with my learning process but what I really want to use with it is Kali as my UNIX/Linux platform to learn off of since I already wanted to learn Cyber Sec. anyways. I just wanted to know if... (12 Replies)
Discussion started by: ApacheOmega
12 Replies

2. UNIX for Dummies Questions & Answers

Red Hat Linux question on top and vmstat outputs

RHEL 5.4 Our Linux machine seemed to be running slow. So, I ran the top and vmstat commands. Question1. I can see the process 11517 consuming 100% CPU . But that just means that this process totally utilizes one of the cores in a mult-core CPU. Right ? This machine apparently has two... (2 Replies)
Discussion started by: kraljic
2 Replies

3. Red Hat

Setting Up live FTP Server with Static IP in Red-Hat Linux 6

Hi Guys, I want to some guidance from you in setting up the Live FTP server in Redhat Linux 6 with Static IP 120.50.150.50. Now should I set my Static Public IP directly to my Linux machine? If so what whould be my sunbet mask? Is any type of natting required here? if so where would... (2 Replies)
Discussion started by: manalisharmabe
2 Replies

4. UNIX for Dummies Questions & Answers

how to know if i use "Red Hat Enterprise Linux" or "Red Hat Desktop" ?

how to know if i use "Red Hat Enterprise Linux" or "Red Hat Desktop" ? (2 Replies)
Discussion started by: ahmedamer12
2 Replies

5. Red Hat

Red Hat Linux release 9 (Shrike) question

Hi guys, wondering if you could help me out here... this is a proxy system problem I'm trying to access a web gui service off a linux box running Red Hat Linux release 9 (Shrike) used as a proxy server which does not seem to have a web browser installed..... how can i do this? so to... (2 Replies)
Discussion started by: slashbash
2 Replies

6. Linux

Red Hat Linux 9

Hello there! Will anybody please tell me some good links to online eBooks on Red Hat Linux 9 user experiences and the like. If the books are in PDF Format, it will be nice to read. Thanks for cooperation in advance. Enjoy using open source and breathe freely! JAM (5 Replies)
Discussion started by: Jawwad
5 Replies

7. Linux

Red-hat AS 2.1 network question

I have setup a AS 2.1 server with no X running or installed. I need to know how to configure the IP and such from command line and change it from DHCP. We used DHCP at first since we didn't know the IP we were going to use and now I need to change it. Any help would be great as Redhat's site just... (2 Replies)
Discussion started by: Acleoma
2 Replies

8. UNIX for Dummies Questions & Answers

Red Hat 7.2 Linux Server - FTP Problems

I have just installed RH7.2 Server and along with apache 1.3 and PHP. I am able to FTP from my linux box to other remote maches, but am unable to FTP to the linux box from other remote machines. The message I get is: A remote host has refused an attempted connect operation. I have done some... (3 Replies)
Discussion started by: jyoung
3 Replies

9. Shell Programming and Scripting

Trouble with FTP Linux red hat

Hi everyone, I Just finished installing Red Hat 7.1 server, and I am having a problem with FTP, and Telnet. I can FTP and Telnet to all client stations. But cannot FTP and Telnet to the server. Does any one know what i missed. All client hosts are in the etc/hosts already. (2 Replies)
Discussion started by: Link_02
2 Replies

10. UNIX for Dummies Questions & Answers

Red Hat Linux 6.0

Ok here is my problem i do not know the command to load a driver for my network card in Ted hat linux 6.0 could sombody give me a hand. and if there is anyone that has a list of commands for red hat that would be great also (2 Replies)
Discussion started by: bbutler3295
2 Replies
Login or Register to Ask a Question