Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks- I am currently using the following code to FTP files from a "loc"(given as an option to the script) to /mnt,currently the script copies the files to be FTP'ed locally and then FTP's,is there a way I can FTP the files from "loc" without copying locally?

#!/usr/bin/perl -w use strict; use warnings; use Cwd qw(getcwd); use File::Copy; use File::Find; use Net::Telnet; use Net::FTP; my %options=(); GetOptions (\%options, 'loc=s') or die("\nERROR:Invalid Option\n"); my $location= $options{loc}; my %files = map {$_ => 1} qw(data.txt scripts.pl); find(sub { copy($File::Find::name, $cwd) or die "Can't cp $File::Find:: +name: $!" if (delete $files{$_}); }, $location); $ftp = Net::FTP->new("129.186.0.100", Debug => 0) or die "Cannot connect to the target: $@"; $ftp->login("root","root") or die "Cannot login ", $ftp->message; $ftp->cwd("/mnt/data") or die "Cannot change working directory ", $ftp->message; $ftp->binary(); $ftp->put("data.txt") or die "put failed ", $ftp->message;; $ftp->put("scripts.pl") or die "put failed ", $ftp->message; $ftp->quit();
  • Comment on Is there a way to transfer files without copying to local directory
  • Download Code

Replies are listed 'Best First'.
Re: Is there a way to transfer files without copying to local directory
by InfiniteSilence (Curate) on Apr 23, 2011 at 18:27 UTC

    Look, considering that you keep posting the same code (oh, no...here is yet another place) with only minor variations and you still do not seem to understand what you are doing, isn't it time to call it a day and start reading up on the Perl language?

    In your previous post you were looking to copy files to a local directory. Now, in this iteration of the same code, you want to do away with the local copy entirely. Before that you had no clue as to what you were doing and the code you are using was written by wind.

    I hate to admit it, but my kid does this to me all the time when he wants me to do his homework for him. He breaks up a problem into smaller parts and asks what the answer is for each successive part. The end result is that he does not learn the subject matter and the problem only gets worse when the next subject requires a thorough understanding of the previous concepts.

    You have not created an account here; you don't give credit to anyone who has helped you previously or even mention that you are still working on the same problem; it is obvious that you don't know what you are doing. I suggest that you purchase a book on Perl (visit Perl.org for recommendations).

    Celebrate Intellectual Diversity

Re: Is there a way to transfer files without copying to local directory
by wind (Priest) on Apr 23, 2011 at 19:38 UTC

    I second everything InfiniteSilence said.

    You really need to create an account at perlmonks if your going to ask repeated questions, especially if they relate to the same problem. This lets monks more easily track additional information and approaches for your problem that you may not include in each subsequent question.

    Additionally, I also agree that it looks like you need to do some studying of perl, as you already have all the tools you need to solve your newest concern:

    my %files = map {$_ => undef} qw(data.txt scripts.pl); find(sub { $files{$_} ||= $File::Find::name if exists $files{$_}; }, $location); for my $file (keys %files) { print $files{$file} ? "$file found in $files{$file}\n" : "$file not found\n"; }