FTP file upload using perl from local system
14,715
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;
Author by
arka.b
Updated on November 24, 2022Comments
-
arka.b over 1 year
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.
-
Quentin over 10 yearsDefine "not working". What does it do? What error messages are reported?
-
Admin over 10 yearsit is not posting the any files
-
Quentin over 10 yearsWhat is it doing? What error messages are reported? What makes you think it should "post" files (whatever you mean by that)?
-
-
Developer over 10 yearswhat is the problem in my code will u explain why u have downvoted it
-
Admin over 10 yearsfile path i have to pass is relative or absolute
-
Developer over 10 yearspass the complete path from both locations
-
arka.b over 8 yearsthis 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?
-
arka.b over 8 yearswhere do the downloaded files gets saved?
-
Developer over 8 yearsset your location where you want
-
arka.b over 8 yearsI added $sock->recv("/home/rancore/arka/10mega.test") or die $ftp->message; and installed the module IO:Socket:Socks:Wrapper. It did not work.
-
arka.b over 8 yearsGaurav - Can you look into this one? stackoverflow.com/questions/32822411/…