Any command to delete files from source dir after SFTP copy

Hi,

I am currently using SFTP 'put' command to copy all files to remote server and then delete the copied files from source directory.

Can anyone help me with a single command to copy and remove files in one go?

Thanks and Regards,
Chetan Vyas

While sftp'ing !command helps to run command in the local machine. So try if the below one works or post the sftp command your using, to get an idea..

sftp ${USR}@${DEST_HOST} << EOF
mput *.txt
!rm *.txt
EOF

Yeah, I need to do the same operation but with 1 command if possible.

Can you post your script..?

#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

Ok. Then check for sftp command's -b option. It helps you to place all your commands in a file and use the file with -b option

# sample file
$>cat Sftp.bat
pwd
!ls -ltr

$>sftp -b Sftp.bat username@host