Sponsored Content
Top Forums Shell Programming and Scripting Any command to delete files from source dir after SFTP copy Post 302546010 by chetancrsp18 on Wednesday 10th of August 2011 07:42:42 AM
Old 08-10-2011
Code:
#filename=XXGT_IN*.txt
#src_dir=/dgltyi/applmgr/1200/xxgt/12.0.0/ftp/bacs
#dest_dir=insphire
filename=$5
src_dir=$6
dest_dir=$7
echo "File Name: " $filename 
src_dir=`eval echo "$6"`
echo "Source Dir: " $src_dir
dest_dir=`eval echo "$7"`
echo "Destination Dir: " $dest_dir
current_path=$(pwd)
echo "Current Directory is " $current_path
#************To check if source directory is present or not*******************
if [ ! -d "${src_dir}" ]
then
echo 'Source directory Not found' 
exit 1
fi
#*****************************************************************************
#************To check for read permissions on source directory ***************
if [ ! -r ${src_dir} ]
then
echo "Read access permission denied on Source Directory"
exit 1
fi
#*****************************************************************************
#************To check for write permissions on source directory **************
if [ ! -w ${src_dir} ]
then
echo "Write access permission denied on Source Directory"
exit 1
fi
#*****************************************************************************
#************To check for execute permissions on source directory ************
if [ ! -x ${src_dir} ]
then
echo "Execute access permission denied on Source Directory"
exit 1
fi
#*****************************************************************************
#************To change current directory to source directory******************
cd $src_dir
current_path=$(pwd)
echo "After CD In " $current_path

#*****************************************************************************
#Check for filenames matching the filname parameter and count all of them*****
files=`ls $filename | wc -l`
echo "There are $files matching file(s)" 
echo $filename
#*****************************************************************************
#Check if there are any matching files in the source directory, else EXIT****
if [ $files -eq 0 ]
then
echo "No files found"
exit 1
fi
sftp -oPort=22 i_glty@62.189.173.39<<EOF
cd $dest_dir
put $filename
bye
EOF
echo "Successfully moved " $filename
#mv $filename $filename_archived
#echo "All transferrred files are archived"
current_path=$(pwd)
echo "In " $current_path
echo "Script finished"
exit 0


Last edited by pludi; 08-10-2011 at 08:53 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to copy N files from one dir to another

Hi, I have a script that can only handLE limited number of input files. I need to be able to write a command (or a script) that: 1> copies N number of files from one directory (A) to another (B). 2> Files that are moved need to be renamed. 3> Files picked to be moved have... (1 Reply)
Discussion started by: GMMike
1 Replies

2. Shell Programming and Scripting

copy files from one dir to another

Hi , I want to copy files from one dir to anothe dir and check if destination dir exists ,if not exist ,has to create but when executing the below schell script ,the destination directory not exist and exit the shell script. #!/bin/sh src_path=/home/owngdw/abc tgt_path=/home/owngdw/abc/xyz if... (6 Replies)
Discussion started by: mohan705
6 Replies

3. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies

4. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

5. Shell Programming and Scripting

Copy Files to Dir and Check If File Exists

Hi everyone. I am trying to write a bash script that will copy files from one directory to another but I need to be able to check the directory that I'm copying the files to and see if the file already exists. If it does I need to add a number at the end of the copied file. Thanks for your help. (3 Replies)
Discussion started by: snag49ers
3 Replies

6. Shell Programming and Scripting

Copy files from input file with dir structure

hi, I want to copy files from source directory based on input file (or output of previous command) and i want to have the SAME DIRECTORY STRUCTURE. Note that i will have other files and directories which i dont want to copy to destination. For example, dir source has following content:... (22 Replies)
Discussion started by: dragon.1431
22 Replies

7. Shell Programming and Scripting

Copy files and subdirs from dir to a new dir

Hello Comunity I am trying to make a bash shell script that it copies files and subdirs(with files) to a new dir. I would like the dest_dir to contain only subdirectories with files not other subdirs inside. it called : cpflatdir src_dir dest_dir Pleaze help me! Thank you in... (2 Replies)
Discussion started by: BTKBaaMMM
2 Replies

8. Shell Programming and Scripting

files copy to dir

Hi, I have a directory which is having many files. I want to copy 10files at a time to another directory. For example. First 10 files to one directory, then next 10 files to another directory and so on. Please let me know if any work around there for it. Thanks (4 Replies)
Discussion started by: Anjan1
4 Replies

9. Shell Programming and Scripting

Copy files to a dir using from a list

Hi all, I'd very grateful for some help with the following: I have a directory with several subdirectories with files in them. All files are named different, even between different subdirectories. I also have a list with some of those file names in a txt file (without the path, just the file... (5 Replies)
Discussion started by: foracoffee
5 Replies

10. Shell Programming and Scripting

how to copy current date files to another dir

i have directory /abcd and i want to copy all today date files in /xyz directory. i am able to see the files by using below command but not able to understand copy. find . -mtime -1 -type f -exec ls -l {} \; (2 Replies)
Discussion started by: learnbash
2 Replies
FTP_CHDIR(3)								 1							      FTP_CHDIR(3)

ftp_chdir - Changes the current directory on a FTP server

SYNOPSIS
bool ftp_chdir (resource $ftp_stream, string $directory) DESCRIPTION
Changes the current directory to the specified one. PARAMETERS
o $ftp_stream - The link identifier of the FTP connection. o $directory - The target directory. RETURN VALUES
Returns TRUE on success or FALSE on failure. If changing directory fails, PHP will also throw a warning. EXAMPLES
Example #1 ftp_chdir(3) example <?php // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { die("FTP connection has failed !"); } echo "Current directory: " . ftp_pwd($conn_id) . " "; // try to change the directory to somedir if (ftp_chdir($conn_id, "somedir")) { echo "Current directory is now: " . ftp_pwd($conn_id) . " "; } else { echo "Couldn't change directory "; } // close the connection ftp_close($conn_id); ?> SEE ALSO
ftp_cdup(3), ftp_pwd(3). PHP Documentation Group FTP_CHDIR(3)
All times are GMT -4. The time now is 05:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy