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
# 1  
Old 11-11-2014
Deleting local server file from automated FTP script

Hi,

I want to delete a file on the local server, while connected to remote server through FTP.
I am using the below code for this

Code:
                        $FTP_CMD -v -n $HOST <<*! >> $LOGFILE 2>&1 
                        user $USER $PASSWORD
                        cd $DIR
                        put $mainfile
                        ls -l
                        !$RM_CMD /path/test/$file2del >> $LOGFILE 2>&1
*!

The FTP logs tell me that the file gets FTPed but the next command is invalid. Please let me know where I am going wrong.

The variables used are :
Code:
FTP_CMD=/usr/bin/ftp
RM_CMD=/usr/bin/rm


Last edited by jhilmil; 11-11-2014 at 08:51 AM..
# 2  
Old 11-11-2014
I doubt ftp understands your RM_CMD... You know ftp is a quite dumb type of shell, that only understand its own internal commands... look at the man pages, there is a delete, del command

Last edited by vbe; 11-11-2014 at 09:35 AM.. Reason: icodes
# 3  
Old 11-11-2014
But the same command works when I try to connect manually to the FTP server. And I also tried the delete command which is again not working.

I am using
Code:
#!/bin/ksh

Do we have any other alternative?
# 4  
Old 11-11-2014
The issue is that RM_CMD is not environmental variable:

Code:
$ RM_CMD=/usr/bin/rm
$ echo $RM_CMD
/usr/bin/rm

$ ftp
ftp> !echo $RM_CMD

$ export RM_CMD
$ ftp
ftp> !echo $RM_CMD
/usr/bin/rm

Now the question I would have is why using the variable RM_CMD at all? Is there a problem with just specifying "rm"?
# 5  
Old 11-11-2014
This code is giving the same error

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

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

# 6  
Old 11-11-2014
Post the error!
# 7  
Old 11-11-2014
Apologies, wasn't paying attention, didn't notice the hereis document ... LS_CMD didn't need to be an environmental variable. But the leading spaces in front of the "!" are causing the problem:

Code:
$ ftp << eof
                               !rm foo >> bar 2>&1
eof

?Invalid command

But this works:

Code:
$ ftp << eof
!rm foo
eof

If you need the whitespace, try:

Code:
sed -e 's/^ *//' << eof | ftp hostname
    ....
eof

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