Delete File Only If Successful Transfer..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete File Only If Successful Transfer..
# 1  
Old 02-24-2011
Power Delete File Only If Successful Transfer..

Hi.

I have this shell script for ftp..

Code:
ftp -n 12.34.5.67 << EOF
user username password
cd LOCAL/inbox
bin
get JAN_Total.gz
# del JAN_Total.gz
EOF

how do i modify the commented part i.e. del JAN_Total.gz only if that JAN_Total.gz has been successfully transfered to the local server.

Thanks a lot
# 2  
Old 02-24-2011
Perfered solution is to use sftp:
sftp might a better choice, with the -b batchfile flag it will terminate the batch script if a command fails unless the command starts with a '-' character. sftp protocol also includes validation of blocks as there transfered so if file arrives you know it's intacked.

Downside is you need a server that supports it and for batch mode you will also need to setup public key authentication.
If you don't have the option of using sftp you could try ncftpget it supports the -DD option (Delete remote file after successfully downloading it.).

Last edited by Chubler_XL; 02-24-2011 at 11:20 PM..
# 3  
Old 02-24-2011
Power

Quote:
Originally Posted by Chubler_XL
sftp might a better choice, with the -b batchfile flag it will terminate the batch script if a command fails unless the command starts with a '-' character. sftp protocol also includes validation of blocks as there transfered so if file arrives you know it's intacked.

Downside is you need a server that supports it and for batch mode you will also need to setup public key authentication.
Thanks for your response.

But that would not be possible Smilie

Coz this is only 0.1% of my total task contribution.. Smilie
# 4  
Old 02-24-2011
Do you have (or can you get) ncftp/ncftpget installed?
# 5  
Old 02-25-2011
try delete <filename>
# 6  
Old 02-25-2011
Quote:
Originally Posted by Chubler_XL
Do you have (or can you get) ncftp/ncftpget installed?
Nope.. I dont think it's possible.

Coz I'm just on the programming user, not the server admin.

So, is there any other way? Couldnt this be achieved thru the unix programming script?

Thanks.
# 7  
Old 02-25-2011
I've been developing something similar for downloading backups from my server. But I am using SSH and SFTP. What you should do is to first run the following command on the server to create an md5 checksum file:

md5sum foofile>foofile.md5

Then make sure that you download foofile.md5 first and then foofile. Before deleting remote foofile check that the md5 sum matches on the local computer:

md5sum foofile.md5

If it does you know the transfer succeeded and you can delete the file on the remote server. If not you try again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ftp - file transfer and check successful delivery

In shell script, I want to transfer files continuously and make sure transfer is successful. Please advise... how to make sure ftp transfer is successful? Also is there any option such as sftp -b where I can pass multiple put <file name> commands to ftp Thanks! (1 Reply)
Discussion started by: vegasluxor
1 Replies

2. Shell Programming and Scripting

Saving variables to a .sh file and last successful run parm.

I had a script that uses a fair number of variables. My manager just let me know that these variables have to be set in one .sh file. How do I do that? I'm use bash shell. Also At the end of my script I need to save the last successful run. so that when I run it next time, I just this parm to... (3 Replies)
Discussion started by: MJCreations
3 Replies

3. Shell Programming and Scripting

Compare File & Copy Replace if Successful

Hi All, I have written a shell script that creates a backup of my MySQL database. The script performs the following functions: Creates a Backup of the MySQL database Compresses the Backup Copies the Backup to a Remote Server Send an E-Mail displaying the size of the Backup Removes any... (6 Replies)
Discussion started by: SalientAnimal
6 Replies

4. Homework & Coursework Questions

Script to check transfer was successful

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a script that performs a post processing action: The run time environment of the script has the... (2 Replies)
Discussion started by: kenrowe
2 Replies

5. Shell Programming and Scripting

Avoiding file overwrite during file transfer using scp

Hi, I have written a small script to transfer a file from one unix server to other using scp command which is working fine. As I know with scp, if any file with the same name is already present on destination server, it would get overwritten without any notification to user. Could anyone help me... (14 Replies)
Discussion started by: dsa
14 Replies

6. Programming

File transfer in C

HI Can anyone provide me with codes for file transfer server to client or vice versa? Also please explain how to compile those programs in ubuntu terminal as i am totally new to socket programming. Thanks (0 Replies)
Discussion started by: mayhemtrigger
0 Replies

7. UNIX for Advanced & Expert Users

delete line from file if successful partial string found

Id like to delete a line from a file using (preferably a single line unix command) if it contains a certain string pattern. If line contains "abcdef" then delete that line. Help greatly appreciated. (7 Replies)
Discussion started by: cronjob78
7 Replies

8. Shell Programming and Scripting

Delete original wav file if lame was successful encoding.

In a bash script: src=”cooltrack.wav” dst=”cooltrack.mp3” lame $src $dst I would like to add some line that would delete the source wav file like: rm $src but I would like this only if the encoding was successful. What should I include before deleting the original to check that the... (2 Replies)
Discussion started by: Aia
2 Replies

9. UNIX for Dummies Questions & Answers

Transfer the file

Dear all, Can anybody let me know how to automate a file transfer process to a remote m/c thru SFTP , automate means it will not prmpt for password. how i am going to achive this....and what all methods are available or tools are available ???? (2 Replies)
Discussion started by: manas_ranjan
2 Replies

10. Shell Programming and Scripting

Need to delete previous line after successful seearch

i have a file in following pattreen A: Size = 10 B: Size = 0 C: Size = 220 D: Size = 0 i want to Display only Charecters which have which have Size = 0 The Out put Should be B: D: Can Some one Help (7 Replies)
Discussion started by: pbsrinivas
7 Replies
Login or Register to Ask a Question