CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Unable to use NET::FTP with linux flavors for transfering files.

 



dhirajextreme
Novice

Jan 8, 2009, 9:17 PM

Post #1 of 7 (1958 views)
Unable to use NET::FTP with linux flavors for transfering files. Can't Post

hi all,

i am using Net::FTP for transferring some file from my windows box to unix different boxes but it doesn't working with linux machines.

should i use some other modules for sending files. or there is another way to send files (like ssh or rsh) if there is then please send me the solution..

thanks in advance .
Dhiraj.


(This post was edited by dhirajextreme on Jan 8, 2009, 9:18 PM)


perl_slave
Novice

Jan 9, 2009, 10:47 AM

Post #2 of 7 (1954 views)
Re: [dhirajextreme] Unable to use NET::FTP with linux flavors for transfering files. [In reply to] Can't Post

What is the code you are using?


dhirajextreme
Novice

Jan 9, 2009, 10:03 PM

Post #3 of 7 (1949 views)
Re: [perl_slave] Unable to use NET::FTP with linux flavors for transfering files. [In reply to] Can't Post

This is the code i am using to for ftp to linux machine.

sub FtpFile{
my $iFile=$_[0];
my $cFile=$_[1];
my $bmc="/bmc_products";
my $ftp = Net::FTP->new($MachineName, Debug => 0)
or die "Cannot connect to $MachineName";
$ftp->login($username,$passcode)
or die "Cannot login ", $ftp->message;
$fcd = $cdr[0].$bmc;
# print "\n $fcd";
$ftp->cwd($fcd)
or die "Cannot change working directory ", $ftp->message;
# $ftp->binary

$ftp->ascii
or die "Cannot shift to ascii mode ", $ftp->message;
my @lcd = $ftp->pwd()
or die "Cannot print current directory ", $ftp->message;
chomp ($lcd[0]);
print "\n Current Directory in FTP is : $lcd[0] \n";
$ftp->put($iFile)
or die "Cannot put $shFile to the working directory ", $ftp->message;
$ftp->put($cFile)
or die "Cannot put $ctlFile to the working directory ", $ftp->message;
$ftp->quit;
print "\n FTP SESSION DONE .. \n";
#Decl ();
}


perl_slave
Novice

Jan 9, 2009, 11:22 PM

Post #4 of 7 (1946 views)
Re: [dhirajextreme] Unable to use NET::FTP with linux flavors for transfering files. [In reply to] Can't Post

One thing you may want to try, considering you are running this from a Windows machine is to force it into Passive mode. Windows has a nasty habit of using only Active mode instead of Passive, at least natively it does - not sure about the Perl Environment you may be using. You should be able to force Passive mode by adding the following to your code:


Code
 my $ftp = Net::FTP->new($MachineName, Debug => 0, Passive => 1,)



Also any error messages from the script would be nice, as to determine where exactly its dying. You may want to check the server logs as well, it may shed some light on the problem.


FishMonger
Veteran / Moderator

Jan 10, 2009, 6:17 AM

Post #5 of 7 (1939 views)
Re: [dhirajextreme] Unable to use NET::FTP with linux flavors for transfering files. [In reply to] Can't Post

Besides enabling passive mode as perl_slave suggests, I'd enable debug mode to get a better idea of what it's doing.

Besides Net::FTP there are several other options.

Net::SFTP
http://search.cpan.org/author/DBROBINS/Net-SFTP-0.10/lib/Net/SFTP.pm

Net::SSH2::SFTP
http://search.cpan.org/author/DBROBINS/Net-SSH2-0.18/lib/Net/SSH2/SFTP.pm

Net::SCP
http://search.cpan.org/author/IVAN/Net-SCP-0.08/SCP.pm


dhirajextreme
Novice

Jan 23, 2009, 4:49 AM

Post #6 of 7 (1883 views)
Re: [FishMonger] Unable to use NET::FTP with linux flavors for transfering files. [In reply to] Can't Post

hi ,

i wrote following code to connect a linux machine and trying to upload a file ( log.txt ) from current directory to the remote machine

use Net::SSH2;

my $ssh2 = Net::SSH2->new();
$ssh2->connect($host) or die "Could not connect to $host: $!";
$ssh2->auth_password($User,$Pass) or
die "Could not login to $host: $!";
alarm(0);

print " Hurray COnnected";

my $put_file = $ssh2->sftp();
$put_file->mkdir("dhiraj");


$put_file->put("log.txt");
or die "Cannot upload to $host: $!";


But this code is getting failed to upload file even it is getting connected successfully ;why ? Please suggest me..

thanks,
Dhiraj.


FishMonger
Veteran / Moderator

Jan 23, 2009, 7:38 AM

Post #7 of 7 (1880 views)
Re: [dhirajextreme] Unable to use NET::FTP with linux flavors for transfering files. [In reply to] Can't Post

There doesn't appear to be a put method in the module(s), but there is an scp_put method. Have you tried that method?

I seams that a through reading of both (Net::SSH2 and Net::SSH2::SFTP) docs would be in order.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives