Link to home
Create AccountLog in
Avatar of amankhan
amankhan

asked on

Help needed regarding perl script that uses SFTP

Hi,

   Help needed related to the below perl script. It is using SFTP to tranfer files, but i dont find any login info.
Is it trying to transfer from one server to another or on the same server. what the below code is trying to do.

   How can we convert the following code which uses normal ftp.

   while connect to ftp , should we compulsarily write use Net::FTP or is there any other way. If we want to connect
to the same server and transfer from one location to another using ftp, how can we achieve it.

help appreciate.

$copy_from_dir="/home/XFFILES/".$dbname."/priceupd";
$copy_to_dir="/usr/tmp/".$dbname."/priceupd";

# Reteive File using SFTP
  open FT ,"|/usr/local/bin/sftp XFFILES";
  print REQ "|/usr/local/bin/sftp XFFILES\n";
  print FT "cd $copy_from_dir\n";
  print REQ "cd ".$copy_from_dir."\n";
  print FT "lcd $copy_to_dir\n";
  print REQ "lcd ".$copy_to_dir."\n";
  print FT "mget ".$price_file.".csv\n";
  print REQ "mget ".$price_file.".csv\n";
  print FT "bye\n";
  print REQ "bye\n";
  close FT;

# Create File for Report Output to be viewed in Concurrent Manager
$reqfile = $applcsf."/".$applout."/o".$request_id.".out";

# Open File for Writing Output
open (REQ,">>$reqfile") || die "Could not Create";

bye
Avatar of nitinsawhney
nitinsawhney
Flag of India image

Hi,

Net::FTP is the best perl module available to support FTP. In perl if you would like to use any module then you have to write use <Module Name>.

So in this cas it is necessary to write use Net::FTP;

Please visit following link to understand more about the implementaion using Net::FTP.

http://aplawrence.com/Unixart/perlnetftp.html

Cheers!
Avatar of Adam314
Adam314

There is also a module that supports SFTP.  If you want that, see here:
http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm
Avatar of amankhan

ASKER

Hi,

  how to connect to a ftp using perl. also, if we want to run a command at the prompt, then we use system command i think. can u brief me with an example.

 also, to connect to ftp, and run some cd and get commands , how can they be run in perl script.

 help appreciated if briefed with an exampled.

thanks



Hi,

Version of my perl is 5.005_03

How can i aceive ftp on this version.

thnx
use Net::SFTP;    #include Net::SFTP module

#Create sftp object
my $sftp = Net::SFTP->new($host);

#download remote file "foo", save as local file "bar"
$sftp->get("foo", "bar");

hi,

 what does the following do. i need to use this or use ftp without using net::ftp or net::sftp

thnx
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer