We help IT Professionals succeed at work.

Help needed regarding perl script that uses SFTP

amankhan
amankhan asked
on
1,238 Views
Last Modified: 2012-06-27
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
Comment
Watch Question

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!
Top Expert 2009

Commented:
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

Author

Commented:
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



Author

Commented:
Hi,

Version of my perl is 5.005_03

How can i aceive ftp on this version.

thnx
Top Expert 2009

Commented:
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");

Author

Commented:
hi,

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

thnx
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.