2

I'm a bit new to perl and stackoverflow. If I could use a more familiar language I would, unfortunately I cannot due to certain circumstances. Thanks in advance for the help.

Modules Not Installed: Net::SFTP, WWW::CURL, Net::SSH2, Net::SFTP::Foriegn Modules Installed: Net::FTP

I am unable to install modules.

Unable to use Net::FTP Tried Default port and port 22, with a username and password. All I get back from the other box's log when trying to connect is "Did not receive identification string from xx.xx.xx.xx" Also unable to use FTP in command line, times out.

$ftp = Net::FTP->new($box,Port=>22, Debug => 0)
or die print "Error: Cannot connect";
$ftp->login($userBox,$passBox)
or die print "Error: Cannot login";
$ftp->cwd()
or die print "Error: Cannot change to Root";
$ftp->cwd($dir)
or die print "Error: Cannot change to selected directory";
if($copyfile ne "" && $dir ne "")
{
$ftp->put($copyfile, $copyfile);
}
$ftp->quit();

I can manually use SFTP through the linux command line, not FTP, so I have been trying to use the system command to SFTP into the other box. The other box's logs just say "Connection closed by xx.xx.xx.xx"

system('sftp '.$userBox.'@'.$box.' ENDOFINPUT'
.$passBox.'ENDOFINPUT
cd ../../../
put '.$filename.' '.$dir.'
exit
ENDOFINPUT');

If anyone knows how to help me with my problem that'd be great :)

FangerZero
  • 91
  • 1
  • 8
  • SFTP and FTP are two completely different protocols. There is no way to access an SFTP server using Net::SFTP. – salva Nov 07 '12 at 09:21

2 Answers2

1

Let's approach this from another direction... when you say you're "unable to install modules", is that just because you don't have root permission? If that's the case, you can install them locally under a user account instead.

If the machine doesn't have an internet connection to even install them locally, you can use the same technique to install them on a different box, then gzip the entire local directory where you have them installed and copy them to the target machine, and add a "use lib" statement to get at them from your script.

Community
  • 1
  • 1
Tobias J
  • 19,813
  • 8
  • 81
  • 66
  • Hmmm I did not know that I could do such a thing. I'd have to ask a senior to be sure I would be allowed to do something like this. Thanks. – FangerZero Nov 13 '12 at 14:11
0

Are you sure that the $passBox equivalent worked on the shell?

You should be able to set-up passwordless connectivity using key-pairs, which would make THAT problem go away quite quickly.

tink
  • 14,342
  • 4
  • 46
  • 50
  • I have yes replaced the variables putting my credentials directly in the code to see if it was a variable issue or not. And the same credentials were used to SFTP in shell(assuming linux command line) I'm rather noob to linux boxes/perl. So lingo is not the best. – FangerZero Nov 06 '12 at 18:54
  • Let's be specific: what you did in the shell was exactly the same as the here document in perl, and it worked? I'd be rather surprised if it did, quite frankly. I didn't ask whether the credentials are correct, but whether the same syntax worked. – tink Nov 06 '12 at 18:58
  • looking at the code, I accidentally deleted a bit @.@ let me quick fix that but what I put into linux command line. But the only bits that were not the same as the command line the Endofline stuff. sftp USER@BOX USER@BOX pass: input pass connected – FangerZero Nov 06 '12 at 19:01
  • So you entered the password interactively? – tink Nov 06 '12 at 19:03
  • Command line Yes, sorry not able to format, atleast don't know how. So After I typed in the SFTP USER@BOX I was then prompted for a password once I put that password in I was allowed access. – FangerZero Nov 06 '12 at 19:07
  • OK ... short of using expect you WON'T be able to do what you want unless to switch to passwordless authentication. – tink Nov 06 '12 at 19:13
  • Thanks, I'm looking into key-pairs now. – FangerZero Nov 06 '12 at 19:36