1

Requirement:

I want to create a script that will upload files from local system to FTP server in using perl.

Sample Code:

use Net::FTP;
    $ftp = Net::FTP->new("some.host.name", Debug => 0)
      or die "Cannot connect to some.host.name: $@";
    $ftp->login("anonymous",'-anonymous@')
      or die "Cannot login ", $ftp->message;
    $ftp->cwd("/pub")
      or die "Cannot change working directory ", $ftp->message;
    $ftp->get("that.file")
      or die "get failed ", $ftp->message;
    $ftp->quit;

P.S: Newbie in Perl.

3
  • 2
    Define "not working". What does it do? What error messages are reported? Commented Sep 4, 2013 at 6:30
  • it is not posting the any files Commented Sep 4, 2013 at 6:32
  • 2
    What is it doing? What error messages are reported? What makes you think it should "post" files (whatever you mean by that)? Commented Sep 4, 2013 at 6:33

1 Answer 1

5

You can try this code this is working fine for me

use strict;
use warnings;
use Net::FTP;

my ($ftp, $host, $user, $pass, $dir, $fpath);

$host = "";
$user = "";
$pass = "";
$dir = "";

$fpath = "";

$ftp = Net::FTP->new($host, Debug => 0);
$ftp->login($user, $pass) || die $ftp->message;
$ftp->cwd($dir);
$ftp->put($fpath) || die $ftp->message;
$ftp->quit;

print $ftp->message;
Sign up to request clarification or add additional context in comments.

8 Comments

what is the problem in my code will u explain why u have downvoted it
file path i have to pass is relative or absolute
pass the complete path from both locations
this serves only uploading to FTP server. How about downloading the same file now? Another requirement is now I want to repeat this upload/download process inside a loop. How to achieve it?
where do the downloaded files gets saved?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.