Solved

Using SSH and SFTP in Perl for transfering files

Posted on 2007-12-02
6
2,498 Views
Last Modified: 2010-03-25
I need to write a script in Perl that uses SFTP and SSH, for transfering files between windows and unix OS.  The ssh on the windows is Cygwin open ssh.   I  am currenlty working on buliding the script but was looking for a head start., due to a work deadline.   I have done a lot of develpment in perl, but I know that adding the ssh and sftp can be challenging.
Thanks for any assistance.
0
Comment
Question by:davidefish
6 Comments
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 40 total points
ID: 20393574
You could use one the the Perl SFTP modules, or just supply the commands yourself, eg:

open SFTP, "|sftp host" or die "Can not run sftp $!\n";

print SFTP <<EOF;
cd /dir
get file
exit
EOF


0
 

Author Comment

by:davidefish
ID: 20396127
Thanks for the assistance but I was looking for a little more structure relating to perl.    There is a little more substance in the implementation of ssh and sftp in perl.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 40 total points
ID: 20398198
The code I have given will work perfectly for sftp so long as you've setup the ssh keys.

If you want something more "perlish", then look at:

http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm

and

http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm

Note that Net::SFTP uses is written in pure perl and uses Net::SSH::Perl for the underlaying SSH mechanism.  This sort of defeats the purpose if you already have ssh installed.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Accepted Solution

by:
davidefish earned 0 total points
ID: 20792989
I have switched to SCP for now.  I was unsuccessful in getting the above code from perl to work but will continue to look into it.
0
 

Expert Comment

by:Mr_Ragno
ID: 26836091

What does mean SCP?
Tintin said that he had implemented a good solution, just need to setup ssh keys, how can I setup the ssh keys?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 28580578
SCP is for Secure Copy.  It copies files using the SSH protocol.

To create keys: http://pkeck.myweb.uga.edu/ssh/
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now