Sponsored Content
Top Forums Shell Programming and Scripting List the file names available on FTP server before selecting the required file Post 302890850 by anuragpgtgerman on Saturday 1st of March 2014 03:17:38 AM
Old 03-01-2014
List the file names available on FTP server before selecting the required file

Below is my script code.which shows the environment name and then fetch the file from the ftp server but I am facing one issue.The script should be run in both way.We can pass the arguments with script and select the environment name then file name.Here the issue is I am not able to list the files which are residing on the ftp server server so that the user can select the file.

Code:
#!/bin/bash
HOST='ftp.npq.net'
USER='xyz'
PASSWD='abc'
UNZIP='unzip $FILE'
LIST='ls -al'
#File_List='`ls -al`'
export Env="?TBD?";

## Set the following variable.
##
set_Env ()
{
 ## Fetching the Env from where the Build deliverable requiered (last option).
prompt_Env;
}

prompt_Env ()
{
echo -e "\nSelect the Enviornment Name\n";
sleep 1;
select Env in dv pf qa ig pp pn exit;
 do
  if [[ -n ${Env} ]]; then
    echo -e "\n\n - You selected: \"${Env}\"\n"
    break;
  else
    echo -e "\n\n - Invalid selection \"${REPLY}\"...Please try again.\n";
  fi
done
 if [[ ${Env} == "exit" ]]; then
  summary=$(
  echo -e "\n#################### FTP process - Aborted ####################\n";
  echo -e "Warning: User gracefully selected \"${Env}\" option to abort the script operation. Exiting with exit_code=151.";);
  echo "${summary}";
  exit 0;
  fi
}
#prompt_env;
#echo -e "Enter the Name of the file:";
#read FILE;
#DIRECTORY=TRAM/"${Env}"
#if [[ -z ${1} ]]; then
#prompt_env;
#fi

#set "${@}";
for ((i=1;$#>=$i;i++))
do
  argn="\${"$i"}";
  argn="$(eval echo $argn)";
  case "${argn%%=*}=" in
  "Env=")
   Env="${argn#*=}";
   Env="${Env:=?TBD?}";
  ;;
 esac
done

## Check arguments and set them if reqd.
## -------------------------------------

for arg in "Env=${Env}";
do
  ## Get Var=Val pair
  var="${arg%=*}";
  val="${arg#*=}";

  ## Check if mandatory params are not valid, set them if reqd.
  if [[ "${val}" == "?TBD?" ]]; then
     set_${var};
  fi
done

DIRECTORY=TRAM/"${Env}"

echo -n "ENTER the name of the file:";
read FILE
ftp -n $HOST << EOT
ascii
user $USER $PASSWD
cd $DIRECTORY
$LIST
get $FILE
bye
EOT
unzip $FILE
rm $FILE

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting one file from a list

Hi, I am able to do this by brute force but I am just curious if there is a better way of handling things. Basically the scenario is something like this: There are a number of files in a directory: rib.20071224.1759.gz 24-Dec-2007 17:59 132K rib.20071224.1959.gz 24-Dec-2007... (7 Replies)
Discussion started by: Legend986
7 Replies

2. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

3. UNIX for Dummies Questions & Answers

Copying dir (and sub dir) file names from ftp server to txt file in diff server

Hey all, i want to copy only the file names from an ftp server (directory and all sub directory) to a text file in another server (non ftp), i.e. i want to recursively move through directories and copy only the names to a text file. any help is appreciated...thank you in advance (1 Reply)
Discussion started by: deking
1 Replies

4. Shell Programming and Scripting

File renaming from list of names contained in another file

I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile). The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be... (7 Replies)
Discussion started by: netfreighter
7 Replies

5. Shell Programming and Scripting

List of file names

I have the following list of file names stored in $fnames, so that if I do foreach f ($fnames) echo "$f" end I will get n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run1 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run2 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run3... (3 Replies)
Discussion started by: kristinu
3 Replies

6. Shell Programming and Scripting

get file names from the list

Hi Experts, Here is my scenario: Am maintaining a file which has list of logs with complete path and file names like bleow a/b/c/Daily/file1_20111012.log d/e/f/Monthly/file1_20111001.log g/h/Daily/file1_20110120.log i/Daily/file1_20110220.log How to copy the file names frm the list... (7 Replies)
Discussion started by: laxm
7 Replies

7. Shell Programming and Scripting

How to get the dates from a list of file names?

Hi All, I have a .txt file with the list of filenames as given below. /dev_data/dev3/ctl/20120622_Employee.txt /dev_data/dev3/ctl/20120623_Employee.txt /dev_data/dev3/ctl/20120624_Employee.txt I want to read this file & write the dates alone from the filenames into a .done file. ... (6 Replies)
Discussion started by: dsfreddie
6 Replies

8. UNIX for Dummies Questions & Answers

List Directory names which have the file

Hi All, Can any one help me to list out the directory names which contain the specified file. See for example File name : file.201307014.LKT Have the directory structure as below. /app/work/data/INDIA/file.201307014.LKT /app/work/data/AMERICA/file.201307014.KTP... (5 Replies)
Discussion started by: Balasankar
5 Replies

9. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies
ftpconfig(1M)						  System Administration Commands					     ftpconfig(1M)

NAME
ftpconfig - set up anonymous FTP SYNOPSIS
ftpconfig [ftpdir] ftpconfig -d ftpdir DESCRIPTION
The ftpconfig script is executed by the super user to set up anonymous FTP. Anonymous FTP allows users to remotely log on to the FTP server by specifying the user name ftp or anonymous and the user's email address as password. The anonymous users are logged on to the FTP Server and given access to a restricted file area with its own file system root. See chroot(2). The FTP area has its own minimal system files. This command will copy and set up all the components needed to operate an anonymous FTP server, including creating the ftp user account, creating device nodes, copying /usr/lib files, and copying timezone data. The passwd and group files set up have been stripped down to prevent malicious users from finding login names on the server. The anonymous file area will be placed under ftpdir. If the ftp user account already exists, then the current FTP area is used, and the system files in it are updated. All other files are left untouched. This command should be run to update the anonymous FTP area's configuration whenever a system patch is installed, or the system is upgraded. OPTIONS
-d Create a new or update an existing ftpdir without creating or updating the ftp user account. Use this option when creating guest FTP user accounts. OPERANDS
The following operands are supported: ftpdir The absolute pathname of the directory under which the anonymous FTP area is set up. EXIT STATUS
The following exit values are returned: 0 Successful completion 1 Improper usage of the command 2 Command failed ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWftpu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
ftpaddhost(1M), in.ftpd(1M), useradd(1M), chroot(2), attributes(5) SunOS 5.10 1 May 2003 ftpconfig(1M)
All times are GMT -4. The time now is 11:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy