1824971 Members
3243 Online
109678 Solutions
New Discussion юеВ

FTP

 
support_32
New Member

FTP

I have scheduled a FTP script to transfer files from client to ftp server and delete all the files transfred.

Now, I am facing problem where the files not successfully sent also will be deleted.

How can I modify my script so that it will check and delete only files that are successfully sent or how can I make sure the deleted files are "safe" in destination.
7 REPLIES 7
Sanjay Kumar Suri
Honored Contributor

Re: FTP

I can suggest the following:

1. Create a ftpcopy directory somewhere at source.
2. Delete all files in ftpcopy directory.
3. Do the actual ftp.
4. After the ftp is over move the files to a ftpcopy directory instead of deleting.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
KapilRaj
Honored Contributor

Re: FTP

Hi,

There are threads here to find out how to capture ftp return codes . add them in the script . Please note most of them are using perl

Kaps
Nothing is impossible
Andris Mednis
Advisor

Re: FTP

We basically do the same - file copying, but instead of FTP we use OpenSSH scp, sometimes rsync via SSH. HP offers free, officially supported OpenSSH package - see http://www.software.hp.com/portal/swdepot/displayProductInfo.do?productNumber=T1471AA .I think it's easier and more secure - connections are encrypted, ssh/scp commands are "more scriptable" than FTP.
Rory R Hammond
Trusted Contributor

Re: FTP

I have an attachement.
that has a example on how to check transfer.
The attachment is a fragment of a working script.
The fragment should work

The basic scenerio is
ftp the stuff.
logout
ftp again and do a dir on the directory,
capturing the contents and checking it.
if ok I mail completion notice, You can remove file instead of mailing.

Another scenerio is loging back in getting the file puting it to an another file name and doing a compare. (This isn't very desirable because of the file size)

Hope this helps
Rory
There are a 100 ways to do things and 97 of them are right
Marvin Strong
Honored Contributor

Re: FTP

I guess I would ask what type of script it is, perl, posix, csh?

if your using the Net:FTP module in perl

you could build an array of successful transfers or failed tranfers, then remove or not remove(depending on the list you created), the files in that list.

or you could call a perl script that returns 0 for success and non-zero for failures, and test each transfer.
Marvin Strong
Honored Contributor

Re: FTP

simple example:

#!/usr/bin/perl

($host, $user, $pw, $file) = @ARGV;

use Net::FTP;

$ftp=Net::FTP->new("$host");
$ftp->login("$user","$pw");
$ftp->put("$file") && push @success, $file;
$ftp->quit;

foreach $file (@success) {
unlink $file;
}
exit 0;
A. Clay Stephenson
Acclaimed Contributor

Re: FTP

I really consider any ftp'ing that does not do error checking Mickey Mouse. Actually, that applies to any code. Error checking with FTP is a pain from the shell. You have to put FTP in verbose mode and then intepret the output. It is MUCH easier to use Perl's NET::FTP module because the error-checking is free. You could put each file, look at the status or use an ftp dir command between each file. Here's a much easier way:


ftpput.pl -h remhost -l remuser -p passwd -A -d /dir1/dir2 -t 3 -r file1 file2 file3
STAT=${?}
echo "Status = ${STAT}"

Note that the -p passwd argument is optional if you setup a .netrc file (man netrc for details) so that the password does not have to be passed on the command line.

I spent about 3 minutes adding the -r option to an existing version. As each files is successfully put, the source file is removed.

Invoke as ftpput.pl -u for full usage.

If it ain't broke, I can fix that.