Deleting local server file from automated FTP script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting local server file from automated FTP script
# 8  
Old 11-11-2014
This is the error after I execute the script

Code:
./scriptname.sh[51]: -s:  not found
rm: cannot remove .. or .

This is the error in logfile


Code:
Connected to xxx.xxx.xxx.x.
220 dummy FTP server (Version 1.1.214.4(PHNE_38458) Mon Feb 15 06:03:12 GMT 2010) ready.
Remote system type is UNIX.
Using binary mode to transfer files.
331 Password required for myuser.
230 User myuser logged in.
250 CWD command successful.
200 PORT command successful.
150 Opening BINARY mode data connection for a.xml.
226 Transfer complete.
200 PORT command successful.
150 Opening ASCII mode data connection for /usr/bin/ls.
total 0
-rw-rw----   1 myuser     mqm              0 Nov 11 08:31 a.xml
226 Transfer complete.
?Invalid command
221 Goodbye.

# 9  
Old 11-11-2014
Please post an excerpt of your script...
# 10  
Old 11-11-2014
What's /path/test/$file2del pointing to? Also show your PWD.
# 11  
Old 11-11-2014
Removing the white spaces before
Code:
!

is not working.
Here is an excerpt from my script

Code:
        cd /path/test/out
        files2send=`ls *.xml`
        ls -l >> $LOGFILE 2>&1
        echo "\n" >> $LOGFILE 2>&1

        for mainfile in $files2send
        do
                file2del=`echo ${enCfile}.ok`
                $TOUCH /path/test/$file2del

                if [ $? -ne 0 ]
                then
                        echo "${TODAY} : Unable to Create FlagFile \
                        /path/test/$file2del" >> $LOGFILE 2>&1

                        continue
                else
                        echo "${TODAY} : Sending File $mainfile via FTP"  >> $LOGFILE 2>&1
                        echo "\n" >> $LOGFILE 2>&1


                        $FTP_CMD -v -n $HOST <<*! >> $LOGFILE 2>&1
                        user $USER $PASSWORD
                        cd $DIR
                        put $mainfile
                        ls -l

!rm /path/test/$file2del  >> $LOGFILE 2>&1 
*!

My current working directory is
Code:
/path

/path/test/$file2del is a flagfile
Code:
a.xml.ok

which I created in the code.

Last edited by vbe; 11-11-2014 at 12:22 PM..
# 12  
Old 11-11-2014
Reading the ftp] manpage:
Quote:
! [command [args]]
Invoke an interactive shell on the local machine. If there are arguments, the first is taken to be a command to execute directly, with the rest of the arguments as its arguments.
Since you are not running the ftp interactively, the "!" fails. Instead:
Code:
if $FTP_CMD -v -n $HOST << eof >> $LOGFILE 2>&1
user $USER $PASSWORD
cd $DIR
put $mainfile
ls -l
eof
then
  rm /path/test/$file2del
fi

This will delete the file if the ftp was successful.

Be aware that encoding a password in a script is typically considered to be "bad". Please consider using a .netrc file. Or moving to ssh/scp/sftp with keys. If the latter is an option, rsync may be of use.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

2. UNIX for Advanced & Expert Users

why file automatically deleting in ftp server

Iam putting file in ftp server. iam doing ftp to transfer a file to ftp server but after sometime(10 sec) the file is automatically deleting in the ftp. Can i know why this happens. When my friend ftp the file to the same server , the file is not deleting aftersometime... it is there. Can... (1 Reply)
Discussion started by: nani1984
1 Replies

3. Shell Programming and Scripting

Automated script to look for files in FTP Server location.

suppose one file comes in one sever location on MOnday.we have to write a script to automatically get that files and put it in different server location. ---------- Post updated at 10:28 AM ---------- Previous update was at 10:27 AM ---------- Please help me on this (2 Replies)
Discussion started by: sonam273
2 Replies

4. Shell Programming and Scripting

Validating the size of file transferred from ftp server to the local system

Validating the size of file transferred from ftp server to the local system. File type: Text file/Flat file Source System: Windows / Unix Systems Target System is always: Unix Mode of Transfer : ASCII We have generic ftp shell script that transfers the files from different ftp servers. ... (2 Replies)
Discussion started by: jpundalik
2 Replies

5. AIX

Do I need to configure my local windows to FTP files from local windows to a UNIX AIX server?

Hi Friends, I have this script for ftping files from AIX server to local windows xp. #!/bin/sh HOST='localsystem.net' USER='myid_onlocal' PASSWD='mypwd_onlocal' FILE='file.txt' ##This is a file on server(AIX) ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD put $FILE... (1 Reply)
Discussion started by: rajsharma
1 Replies

6. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies

7. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

8. Shell Programming and Scripting

how to FTP a file from the local folder to unix server

Hi All, please help me to write a shell that ftp a file which is in the local (C:\) drive to a Unix server. Where as i know the IP for the Unix server. i could do this process by using ftp command. pls help me to write as Shell script. Thanks in advance for all of your answers.:b::b: (3 Replies)
Discussion started by: little_wonder
3 Replies

9. Shell Programming and Scripting

Automated FTP from Unix to Active Directory Server

Automated Unix to Windows Active Directory FTP I have done many automated FTP scripts using the following logic: =============================== echo "Starting the FTP transfer..." { echo " open 192.168.1.100 user username password ascii put... (1 Reply)
Discussion started by: Cbish68
1 Replies

10. Shell Programming and Scripting

Dowloading a File from FTP Server to a local Server where User Id's are different

Hi, The Setup is like this. I'm connecting to Unix machine from my local machine. After connecting to Unix M/c, i need to connect FTP server. Am successful in connecting to FTP server, but am not able to download the file from the ftp server to my local machine. I have different user id's and... (1 Reply)
Discussion started by: ranjith_taurean
1 Replies
Login or Register to Ask a Question