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.
Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Perl Script to upload file

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

use Net::FTP;

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";

#-- login
$ftp->login($username,$password) or die "Login failed: $!";

#-- chdir to $ftpdir
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";

$ftp->put($file);

#-- close ftp connection
$ftp->quit or die "Error closing ftp connection: $!";

 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd try



 
lowercase baba
Posts: 12988
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget about a script...how would YOU determine if the file was uploaded correctly?
 
Alissa Horner
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:Forget about a script...how would YOU determine if the file was uploaded correctly?



The file that has been uploaded is identical to the file before it was uploaded.
 
fred rosenberger
lowercase baba
Posts: 12988
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alissa Horner wrote:

fred rosenberger wrote:Forget about a script...how would YOU determine if the file was uploaded correctly?



The file that has been uploaded is identical to the file before it was uploaded.


How can you tell if it is identical?

I'm trying to get you to think through the issue. Pretend that you have a paper document in a box at your house. You tell your intern to photocopy it, and take that to my house.

Now, how can you tell if the two documents are the same? What kinds of things can we look at? You can call me and ask me questions...what would you ask?
 
Marshal
Posts: 26613
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Posts: 12988
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic