Using SSH and SFTP in Perl for transfering files

Posted on 2007-12-02
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.
Question by:davidefish
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Assisted Solution

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


Author Comment

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.
LVL 48

Assisted Solution

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:


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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

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.

Expert Comment

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?
LVL 39

Expert Comment

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

To create keys:

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

729 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