Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help needed regarding perl script that uses SFTP

Posted on 2007-10-03
7
Medium Priority
?
1,216 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
0
Comment
Question by:amankhan
  • 3
  • 3
7 Comments
 
LVL 6

Expert Comment

by:nitinsawhney
ID: 20005550
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!
0
 
LVL 39

Expert Comment

by:Adam314
ID: 20006375
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
0
 

Author Comment

by:amankhan
ID: 20006481
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



0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:amankhan
ID: 20006616
Hi,

Version of my perl is 5.005_03

How can i aceive ftp on this version.

thnx
0
 
LVL 39

Expert Comment

by:Adam314
ID: 20006912
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");

0
 

Author Comment

by:amankhan
ID: 20008215
hi,

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

thnx
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 20009921
The above code will log into an SFTP server and get a file.
Why don't you want to use a Net::SFTP or Net::FTP module?  That is the standard method?

You could try this:
open FTP ,"|/path/to/ftp $host";
print FTP "$username\n";
print FTP "$password\n";
print FTP "get foo\n";
print FTP "quit\n";
close(FTP);

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question