This week's book giveaway is in the Spring forum. We're giving away four copies of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 and have Marten Deinum & Iuliana Cosmina on-line! See this thread for details.
I'm writing a Perl script to upload a file via FTP. How would I get the script to verify whether the file was uploaded correctly? How would I get my script to keep trying to upload the file if the upload failed for a maximum of 3 attempts?
Here is a portion of my script:#!/usr/bin/perl
my $host = "rnpdb001.copart.com";
my $username = "SQLGBRUSR";
my $password = "BRET";
my $ftpdir = "/omniture";
my $file = "yourfile.txt";
#-- connect to ftp server
my $ftp = Net::FTP->new($host) or die "Error connecting to $host";
$ftp->login($username,$password) or die "Login failed: $!";
#-- chdir to $ftpdir
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";
#-- close ftp connection
$ftp->quit or die "Error closing ftp connection: $!";
I know almost nothing about Perl, but what I know about FTP makes me wonder why the put() function doesn't have an "or die" option. It's certainly possible for errors to occur during the upload, and it's important for you to know when that has happened. Otherwise you get led down into the dark cave of wondering how you know whether the upload completed; you shouldn't have to do that in a proper FTP client implementation.
most ftp clients i've used - perl or not - do give some kind of return code. timeout, file-not-found, unable to write to directory, etc. "..or die" always seems a little harsh to me.
What we generally do is check for a return or error code. If we are paranoid, we will also do an "ls" on the files (local and remote) and compare the sizes.
I suppose if you were REALLY paranoid, you could pull a copy BACK, and compare it with the original. If it matches, you can be pretty sure all is well. If it doesn't, you can't tell if the problem was with the original put, or the secondary get.
I suppose it is possible that some error occurs on the put, and by some miracle, another error that reverts the original error could happen on the get, but the odds of that I would estimate are as close to zero that i'm not sure anyone could detect a difference.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors