<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>twistedgenes.com - Blogs by Rakesh Gupta &#187; FTP</title>
	<atom:link href="http://www.twistedgenes.com/tag/ftp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.twistedgenes.com</link>
	<description>Blogs on truth, technology, food, linux, leisure, experiences, adventure, romance, friends etc !</description>
	<lastBuildDate>Sat, 12 Jun 2010 14:24:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A strikingly odd web application exposure</title>
		<link>http://www.twistedgenes.com/2008/12/a-strikingly-odd-web-application-exposure/</link>
		<comments>http://www.twistedgenes.com/2008/12/a-strikingly-odd-web-application-exposure/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 19:06:39 +0000</pubDate>
		<dc:creator>Rakesh</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Crazy]]></category>
		<category><![CDATA[Experiences]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[all]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Curl]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://www.twistedgenes.com/?p=124</guid>
		<description><![CDATA[Without having to expose your backend stuff to the internet, how do you service a WAP/WEB request. The blog below discusses a typical method of achieving the same. Assuming that whole web system is being developed in a intranet and not hosted outside. Let us call the internal unexposed server as A. We need a [...]]]></description>
			<content:encoded><![CDATA[<p>Without having to expose your backend stuff to the internet, how do you service a WAP/WEB request. The blog below discusses a typical method of achieving the same. Assuming that whole web system is being developed in a intranet and not hosted outside. Let us call the internal unexposed server as A. We need a server hosted on internet to fetch the WAP/WEB requests from the mobile or computer. This server is called as B. The request is being fired on the server B, the request is written to a flat file called request file. Server A runs a shell program viz fetchrequest.sh which reads the request file every second for any new requests coming  using the curl unix utility. Meanwhile, the server B sleeps off and waits for a response from server A. Server A will read the request and if its new (newness of a request is determined by saving the previous  request number in a global shell environment variable) server A processes it and shoots back the response to server B in the form of a file via FTP. Server B, in its sleeping state waits for the this FTP response file. Once recieved, it pushes back the response to the user. The whole wait process is scheduled for a fixed period of time, after which a dummy response is send like server is down, request failed, bla bla etc . Let us see how the same is achieved in fetchreques.sh running on server A.</p>
<p>File fetchrequest.sh</p>
<pre>
#!/bin/bash
while [ 10 -eq 10 ]

#Runs in a infinite loop checking request file at server B every second
do
if [ `env | grep -c lastCounter` = 1 ];then
newCounter=`curl -s http://serverB/requestFile.txt | tail -1 | cut -d: -f1`

#Reading request file at server B
param=`curl -s serverB/requestFile.txt | tail -1 | cut -d: -f2` #Extracting the request parameters
echo newCounter : $newCounter lastCounter : $lastCounter

#If there is a new request, sending a response back to the server B
if [ "$newCounter" != "$lastCounter" ]; then
echo "Need to send a response"
echo "Response URL : http://serverA/something.pl?action=something&amp;param1&amp;param2"

#Trimming of the response that needs to be send to serverB and storing it in a variable
output=`curl -s "http://serverA/something.pl?action=something&amp;param1&amp;param2" | grep 'cap\\|img' |
sed \ 's/&lt;src&gt;.*&lt;\/src&gt;//g;s/&lt;cap&gt;/\:/g;s/&lt;\/cap&gt;//g;s/&lt;img&gt;/\:/g;s/&lt;\/img&gt;//g'`
echo "Response received : $output"

#writing the response to a flat file to be FTPed to server B
`echo $output&gt;"rp_$newCounter.txt"`
`export filename==rp_$newCounter.txt`
`echo ls -l "rp_$newCounter.txt"`
typeset -i responseSize=`wc -c rp_$newCounter.txt | cut -d" " -f1`
echo "Response size $responseSize"

#If the process response is garbled, small or null, sending a dummy error in FTP file
if [ $responseSize = 1 ];then
`echo "We are working , try later" &gt; "rp_$newCounter.txt"`
fi

#making an FTP connection to serverB and launching the response file
`curl -s -T "rp_$newCounter.txt" -u username:password"ftp://serverB/rp_$newCounter.txt"`
echo "Uploaded the FTP file for $newCounter request"
`rm -f rp_$newCounter.txt`
echo "Deleting rp_$newCounter.txt after upload"

#Updating the request environment variable
lastCounter=$newCounter
export lastCounter
fi
else
lastCounter=`curl -s http://serverB/mobRequests.txt | tail -1 | cut -d: -f1`
export lastCounter
fi
done
</pre>
<p>The whole system works very well, and the requests are processed and response send to user. There are however limitations to this model.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twistedgenes.com/2008/12/a-strikingly-odd-web-application-exposure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4811008-2");
pageTracker._setDomainName(".twistedgenes.com");
pageTracker._trackPageview();
} catch(err) {}</script>