anavagomez has asked for the wisdom of the Perl Monks concerning the following question:

hello, i have a perl script that runs on a windows 2008 server as an schedule task. This script pulls data from one of our vendros' database and then writes out the data in an XML file. The file is saved on the c:\wtxml directory. I need help with a script that will take that XML file and upload it to a Linux server - Redhat, and place it in a directory: /opt/contrib-qa/apache/httdocs/wtxml/ The way I access the Linux server manually, is using SecureFX with a SFTP protocol: contrib-qa-myserver.com, port 22, user, password. I do not have access to the root user, but I have control in all directories inside /opt/contrib-qa/ I know that the Linux server does not run a ssh server, it only runs an ssh client. I am really confused, and unsure on how to do this, at a simple glance it does not look as a very difficult task, but with the scarce resources that I have, and the limited knowledge of the technology it becomes a real challenge. I am providing a copy of the script that writes the XMl file. The move of the file, can either be a separate script, or just an addition to this current one, what ever makes more sense. Any help is very much appreciated. Thank you.
#!/usr/local/bin/perl use warnings; use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft ActiveX Data Objects'; use XML::Generator::DBI; use XML::Handler::YAWriter; use XML::DOM; my $doc = XML::DOM::Document->new(); my $xml_pi = $doc->createXMLDecl ('1.0'); my $root = $doc->createElement('DATA'); my $objConn = Win32::OLE->new("ADODB.Connection"); my $objCommand = Win32::OLE->new("ADODB.Command"); my $objRecordSet = Win32::OLE->new("ADODB.Recordset"); $objConn->Open("Driver={Webtrends ODBC Driver};Server=webtrend1;Port=7 +099;Database=flrdacbkoji.wct;Uid=****;Pwd=*****;AccountId=1;Language= +english;ProfileGuid=KlDwrNbKgm6;SSL=0;"); $objCommand->{"ActiveConnection"} = $objConn; $objCommand->{"CommandText"} = "SELECT * FROM Pages WHERE Titles <> '' + AND URLs IS NOT NULL AND Titles NOT LIKE House TV : 404 Error Page' +AND Titles NOT LIKE '302 Found' AND URLs <> 'http://housetv.com/' AND + URLs <> 'http://housetv.com/index.htm' AND URLs <> 'http://housetv.c +om/wcm/idcplg/' ORDER BY Visits DESC"; $objRecordSet->{"CursorLocation"} = 3; #adUseClient $objRecordSet->{"CursorType"} = 0; #adOpenForwardOnly $objRecordSet->{"LockType"} = 1; #adLockReadOnly; $objRecordSet = $objCommand->Execute(); my ($rec, $col, $val); while (!$objRecordSet->EOF) { $rec = $doc->createElement('RECORD'); $root->appendChild($rec); $col = $doc->createElement('FIELD'); $col->setAttribute ("Name", "Titles"); $rec->appendChild($col); $val = $doc->createTextNode($objRecordSet->Fields("Titles")->val +ue); $col->appendChild($val); $col = $doc->createElement('FIELD'); $col->setAttribute ("Name", "URLs"); $rec->appendChild($col); $val = $doc->createTextNode($objRecordSet->Fields("URLs")->value +); $col->appendChild($val); $col = $doc->createElement('FIELD'); $col->setAttribute ("Name", "Visits"); $rec->appendChild($col); $val = $doc->createTextNode($objRecordSet->Fields("Visits")->val +ue); $col->appendChild($val); $col = $doc->createElement('FIELD'); $col->setAttribute ("Name", "Views"); $rec->appendChild($col); $val = $doc->createTextNode($objRecordSet->Fields("Views")->valu +e); $col->appendChild($val); $objRecordSet->MoveNext(); } print $xml_pi->toString; print $root->toString; $root->printToFile ("C:\\wtxml\data.xml");

Replies are listed 'Best First'.
Re: how to transfer a xml file to server
by dasgar (Priest) on Oct 20, 2010 at 18:51 UTC

        I know that the Linux server does not run a ssh server, it only runs an ssh client.

    Are you sure about that? I'm not a Linux expert or anything, but I believe that by default, most Linux distributions (for sure Red Hat) have the ssh server installed and running. Also, I believe (but could be wrong) that the SFTP service is running under the ssh service. In other words, if the ssh service is turned off, then the SFTP service is off too. Now to get off this side trail of thinking out loud...

    Anyways, it sounds like manually you're using an SFTP client. In that case, using something like Net::SFTP, Net::FTPSSL, or Net::SCP might do the trick, depending on which protocol you're actually using. I'd suggest testing it out in a separate script to see if you can transfer a file. Once you've got the kinks worked out, then you can decide if it's easier to incorporate it into your existing script or keep it separate.

Re: how to transfer a xml file to server
by hbm (Hermit) on Oct 20, 2010 at 18:56 UTC

    I'm puzzled that your linux server doesn't have ssh and yet you connect on port 22... But, I only know of SecureFX what I've just read on its website.

    I think the first thing you should do is set up a key so you can connect without entering a username and password. SecureFX's website describes a Public Key Assistant for uploading a public key to the server.

    If you can get that going, and if SecureFX has a commandline interface, you could just call it from your script, with the appropriate arguments.

    For similar tasks, I've used PuTTY's pscp.exe and pagent.exe. From perl, call the latter to load your key locally; and then call pscp.exe with the local file path and the remote destination.

      I'm puzzled that your linux server doesn't have ssh and yet you connect on port 22...

      sftp requires ssh to function, so the box does have an ssh server. When he said "I know that the Linux server does not run a ssh server", he was mistaken, or he meant he can't access a shell that way.

Re: how to transfer a xml file to server
by Illuminatus (Curate) on Oct 20, 2010 at 20:41 UTC
    Is there a reason why Net::SFTP::Foreign is not an option? I can't say I've ever used it, but the page does not indicate that it won't work on Windows.

    fnord

      It could work, but one would first have to install a "compatible ssh command".