Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to upload file to the right path using FTP module in Perl

Status
Not open for further replies.

022267

IS-IT--Management
Nov 6, 2002
5
US
Hi, folks,
Here is my question.
Perl script in windows.

#! usr/bin/perl
use NET::FTP;
$upload_ftp_site = "xx.xx.x.xx";
$userid = "xxx";
$passwd = "xxxxxxxx";
$local_file = "C:\\path1\test.txt";
$ftp = Net::FTP->new($upload_ftp_site, Timeout=>30, Debug=>0);
$ftp->login($userid, $passwd) || die("ID $Login/$Passwd : $!\n");
$ftp->binary();
$ftp->cwd("remote_dir\\ftp\\");
if ($ftp->put("$local_file")) {
print"Ok\n";
}
else {
print "error\n";
}

the script always puts the file in the root path "home\\ instead of "home\\
I tried the cwd as "home\\ "\\home\\ " "\\ and "\\remote_dir\\ftp\\". they didnot work.

My userid and passwd are used to login to "home\\ of the remote server if I ftp through cmd window.
can anyone help me to work it out? thanks.
 
see if this is of help


Code:
#! usr/bin/perl

use NET::FTP;
use File::Basename;

$upload_ftp_site = "xx.xx.x.xx";
$userid = "xxx";
$passwd = "xxxxxxxx";
$local_file = "C:\\path1\\test.txt";
($name,$path,$suffix) = fileparse($fullname);
$basename = basename($local_file);

$ftp = Net::FTP->new($upload_ftp_site, Timeout=>30, Debug=>0);
$ftp->login($userid, $passwd) || die("ID $Login/$Passwd : $!\n");
$ftp->binary();
if ($ftp->put("$local_file", "remote_dir\\ftp\\$basename")) {
    print"Ok\n";
}
else {
    print "error\n";
}
---
cheers!
san.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top