Question

I have an existing Perl script that uses the FTP object to send a couple of files to an AIX box. I just discovered that our Linux box does not support FTP. It does support SFTP. What steps should I go through to convert my script to use SFTP?

Was it helpful?

Solution

Your current script is probably using the Net::FTP module. You'll need the Net::SFTP module and its dependencies from CPAN. You may just even start a new script using the existing one as a guide. The logic is the same, though. Connect, send, and disconnect.

OTHER TIPS

I've actually done something similar. But it was to prepare any current FTP script to be run via SFTP when needed.

I made a wrapper object around Net::SFTP which looks and acts like a Net::FTP object. Therefore, all the calls could be left in places with a different implementation.

I went from this:

my $client = Net::FTP->new( Host => 'ftp.somehost.com', ... );

to

my $client = FTPClient->new( Host => 'ftp.somehost.com', ...
                           , secureFTP => 1 
                           ); 

And just implemented all the methods I was using from Net::FTP in my new class. Net::SFTP gives back some different returns, so you have to actually wrap function instead of just using something like Class::Delegator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top