<?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>Web2.0 Tutorials &#187; Zulutown Webmaster</title>
	<atom:link href="http://www.zulutown.com/blog/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zulutown.com/blog</link>
	<description>All the Guides You Need to Become a Web2.0 Expert</description>
	<lastBuildDate>Mon, 13 Jul 2009 07:50:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ajax Dynamic Content with Struts2, JQuery and JSON plugin</title>
		<link>http://www.zulutown.com/blog/2009/07/12/ajax-dynamic-content-with-struts2-jquery-and-json-plugin/</link>
		<comments>http://www.zulutown.com/blog/2009/07/12/ajax-dynamic-content-with-struts2-jquery-and-json-plugin/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 19:46:02 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Struts2]]></category>
		<category><![CDATA[actionsupport]]></category>
		<category><![CDATA[dynamically]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json-default]]></category>
		<category><![CDATA[jsonplugin]]></category>
		<category><![CDATA[JSONResult]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[struts-default]]></category>
		<category><![CDATA[struts-plugin.xml]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=118</guid>
		<description><![CDATA[This guide explains how to create a simple web application that dynamically populates a page through AJAX, using both Struts2 and the JSON features of JQuery.
﻿First of all it&#8217;s required the Json Plugin (available at http://jsonplugin.googlecode.com) that should be placed in the /WEB-INF/lib/ directory (where obviously are placed all the Struts2 jar as explained in [...]]]></description>
			<content:encoded><![CDATA[<p>This guide explains how to create a simple web application that dynamically populates a page through AJAX, using both Struts2 and the JSON features of JQuery.<br />
﻿First of all it&#8217;s required the Json Plugin (available at <a href="http://jsonplugin.googlecode.com" target="_blank">http://jsonplugin.googlecode.com</a>) that should be placed in the <code>/WEB-INF/lib/</code> directory (where obviously are placed all the Struts2 jar as explained in other tutorials of this site).</p>
<p>The plugin adds (through its struts-plugin.xml) a new result type defined this way:</p>
<pre>&lt;package name="json-default" extends="struts-default"&gt;
 &lt;result-types&gt;
  &lt;result-type name="json" class="com.googlecode.jsonplugin.JSONResult"/&gt;
 &lt;/result-types&gt;
 ...
&lt;/package&gt;</pre>
<p>Since it&#8217;s defined in the <code>json-default</code> package, in order to use that result inside custom action mappings, there are two choices:</p>
<ul>
<li> the packages containing actions with <code>json</code> result-type have to extend the package <code>json-default</code> and not, as usual, the <code>struts-default</code> package</li>
<li>in the packages where <code>json</code> result-type is used, it&#8217;s to possible to add the previous <code>&lt;result-types&gt;...&lt;/result-types&gt;</code> lines that simply refers to a class contained in the json plugin <code>.jar</code> added to the application.</li>
</ul>
<p>It&#8217;s now possible to define action mappings using <code>json</code> as result type, like the following one:</p>
<pre>&lt;package name="testPackage" extends="json-default" namespace="/test"&gt;
 &lt;action name="giveMeJsonData" class="testAction" method="giveMe"&gt;
  &lt;result type="json"&gt;
   &lt;param name="root"&gt;jsonData&lt;/param&gt;
  &lt;/result&gt;
 &lt;/action&gt;
...
&lt;/package&gt;</pre>
<p>The above definition states that the url <code>/test/giveMeJsonData.action</code> will cause the execution of the method <code>public String giveMe()</code> defined inside the class <code>testAction</code> (in this case it&#8217;s a Spring managed bean, but it can be even a qualified name of a Struts2 action class, obviously extending ActionSupport class).</p>
<p>The result of that action (with a <code>SUCCESS</code> result code) is the json data structure stored in the <code>jsonData</code> property of the action class, and so available through its getter <code>getJsonData()</code>.</p>
<p>An example of the behavior for <code>giveMe()</code> method:</p>
<pre>public String giveMe() {
 jsonData = new LinkedHashMap&lt;String, Object&gt;();
 jsonData.put("shoppingCartId", getCartId());
 jsonData.put("datetime", new Date());
 Set&lt;Map&lt;String, Object&gt;&gt; items = new HashSet&lt;Map&lt;String, Object&gt;&gt;();
 for (Item item : businessMethod.findItemsForCart(getCartId())) {
  HashMap&lt;String, Object&gt; itemMap = new HashMap&lt;String, Object&gt;();
  itemMap.put("id", item.getId());
  itemMap.put("quantity", item.getQuantity());
  itemMap.put("price", item.getPrice);
  items.add(itemMap);
 }
 jsonData.put("items", items);
 return SUCCESS;
}</pre>
<p>The final step is to use JQuery to call (on a specific event) through AJAX the URL where the action has been defined, and obviously to use the returned data to dynamically populate the page HTML.</p>
<pre>function testingJsonAndAjax(cartId) {
 $.getJSON(
  /test/giveMeJsonData.action ,
  {
   cartId: cartId
  },
  function(json) {
   $('#cartId').html(json.shoppingCartId);
   $('#cartCreation').html(json.datetime);
   itemsHtml = "&lt;table&gt;";
   for (i in json.items) {
    itemsHtml += “&lt;tr&gt;”;
    itemsHtml += “&lt;td&gt;” + json.items[i].id + “&lt;/td&gt;”;
    itemsHtml += “&lt;td&gt;” + json.items[i].quantity + “&lt;/td&gt;”;
    itemsHtml += “&lt;td&gt;” + json.items[i].price + “&lt;/td&gt;”;
    itemsHtml += “&lt;/tr&gt;”;
   }
   itemsHtml += “&lt;/table&gt;”;
   $('#cartItems').html(itemsHtml);
  }
 );
 return false;
}</pre>
<p>A sample HTML would look like this</p>
<pre>Cart 32233 &lt;a href=”#” onclick="return testingJsonAndAjax(32233)&gt;Refresh&lt;/a&gt; &lt;br /&gt;
Cart 82382 &lt;a href=”#” onclick="return testingJsonAndAjax(82382)&gt;Refresh&lt;/a&gt; &lt;br /&gt;

&lt;div id=”cartId”&gt;JQuery will replace this text with the Cart Id returned by the json action&lt;/div&gt;
&lt;div id=”cartCreation”&gt;JQuery will replace this text with the Cart creation date returned by the json action&lt;/div&gt;
&lt;div id=”cartItems”&gt;Jquery wil replace this text with a HTML table containg all the items of the selected cart&lt;/div&gt;</pre>
<p>The <code>id</code> will be used by the JQuery selector to determine in which of them the data returned by the json action will be written in.</p>
<p>I hope this tutorial has been useful for a simple introduction to AJAX and JSON using JQuery and Struts2.</p>
<p><strong>EDIT 1:</strong> on the Struts User Mailing List, <a href="http://www.manning.com/wannemacher">Wes Wannemacher</a> suggested that it would be better to directly put the item object inside the root object returned through JSON.</p>
<p>This is absolutely right and would lead to cleaner code. But I didn&#8217;t used that technique for a security reason, i.e. if the Item object is a JPA entity, it may contain some properties that is better not to show to the end users. In the case of a User entity, it would be no good to return in the json data its hashed password.</p>
<p>So I created that <em>ugly</em> workaround, defining some HashMaps and putting there just the specific properties I wish to return in the Json result (and maybe this will save too some HTTP traffic <img src='http://www.zulutown.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )</p>
<p><strong>EDIT 2:</strong> on the Struts User Mailing List, Nils-Helge Garli Hegvik suggested that it&#8217;s even possible to use the &#8220;includeProperties&#8221; or &#8220;excludeProperties&#8221; parameters (as described <a href="http://cwiki.apache.org/S2PLUGINS/json-plugin.html">here</a>) in the result configuration to simply return some objects and the JSON plugin will do the trick of filtering just the specific properties to show.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">in the packages where “json” result-type is used, it&#8217;s to possibile to add the previous &amp;lt;result-types&amp;gt;&#8230;&amp;lt;/result-types&amp;gt; lines that simply refers to a class contained in the .jar added to the application (contained in the json-plugin jar).</div>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/07/12/ajax-dynamic-content-with-struts2-jquery-and-json-plugin/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Hibernate, hashCode, equals and Eclipse</title>
		<link>http://www.zulutown.com/blog/2009/04/12/hibernate-hashcode-equals-and-eclipse/</link>
		<comments>http://www.zulutown.com/blog/2009/04/12/hibernate-hashcode-equals-and-eclipse/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 09:18:57 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[automatic generation]]></category>
		<category><![CDATA[bean]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[contains]]></category>
		<category><![CDATA[embeddedId]]></category>
		<category><![CDATA[equals]]></category>
		<category><![CDATA[fetch]]></category>
		<category><![CDATA[getters]]></category>
		<category><![CDATA[hashcode]]></category>
		<category><![CDATA[instanceof]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lazy loading]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[proxy class]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=115</guid>
		<description><![CDATA[Java programmers use often Eclipse to write their code, and it&#8217;s common to rely on the Eclipse features to quickly generate the hashCode() and equals(Object obj) methods of the beans.
Working on a Hibernate based application, I often noticed unexpected issues, and after some in depth debugging I&#8217;ve found that probably some of these problems were [...]]]></description>
			<content:encoded><![CDATA[<p>Java programmers use often Eclipse to write their code, and it&#8217;s common to rely on the Eclipse features to quickly generate the <em>hashCode()</em> and <em>equals(Object obj)</em> methods of the beans.</p>
<p>Working on a Hibernate based application, I often noticed unexpected issues, and after some <em>in depth</em> debugging I&#8217;ve found that probably some of these problems were caused by the Eclipse automatic generation of <code>equals</code> method.</p>
<p>In my opinion, this is mostly caused by the fact that Hibernate generates on top of our <em>entity bean</em> classes other <em>proxy classes</em> that overrides the getters, and other methods in order to provide the <em>lazy loading</em> of data.</p>
<p>I.e.: When Hibernate loads from the DB a <code>Movie</code> bean, it will have, for example, an associated list of <code>MovieActor</code> objects. Obviously Hibernate will not fetch all the data related to every single actor, but anyway it will generate the <em>stub</em> for the MovieActor objects.</p>
<p>The programmer would be tempted to use code like this:</p>
<pre>Movie aMovie = getEntityManager.find(...);
MovieActor aMovieActor = getEntityManager.find(...);
if (aMovie.getActors().contains(aMovieActor)) {
	System.out.println(aMovieActor.getActor().getName() + " acted in the movie " + aMovie.getTitle());
}</pre>
<p>I noticed that <code>contains</code> method often returns <code>false</code> even if that actor really acted in that movie!<br />
After some long debugging sessions, my final idea is that the problem is how Eclipse automatically generated the <code>equals</code> method of <code>MovieActor</code> class:</p>
<pre>	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof MovieActor))
			return false;
		MovieActor other = (MovieActor) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}</pre>
<p>In this code <code>id</code> is an <code>@EmbeddedId</code> composed by the Actor and the Movie associations. What I believe that causes problems is: <strong><code>other.id</code></strong>!</p>
<p>This is because probably the Id of the <code>other</code> object hasn&#8217;t been loaded yet, and its fetching will happen on the calling of <code>getId()</code> of the proxy class built on MovieActor.</p>
<p>So, I changed the <code>equals</code> method this way:</p>
<pre>	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof MovieActor))
			return false;
		MovieActor other = (MovieActor) obj;
		if (id == null) {
			if (other.getId() != null)
				return false;
		} else if (!id.equals(other.getId()))
			return false;
		return true;
	}</pre>
<p>And after this little change, <code>contains</code> began to work correctly!</p>
<p>Another <strong>very important</strong> thing is to check <em>use &#8216;instanceof&#8217; to compare types</em> otherwise some ugly code would be generated.<br />
Some checks like <code>if (getClass() != obj.getClass())</code> would miserably fail when hibernate proxy classes are used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/04/12/hibernate-hashcode-equals-and-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Watch P2P Television on Linux with Sopcast and VLC player</title>
		<link>http://www.zulutown.com/blog/2009/04/01/watch-p2p-television-on-linux-with-sopcast-and-vlc-player/</link>
		<comments>http://www.zulutown.com/blog/2009/04/01/watch-p2p-television-on-linux-with-sopcast-and-vlc-player/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 20:43:27 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[myp2p]]></category>
		<category><![CDATA[p2p]]></category>
		<category><![CDATA[p2p tv]]></category>
		<category><![CDATA[p2ptv]]></category>
		<category><![CDATA[peer to peer]]></category>
		<category><![CDATA[sopcast]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[television]]></category>
		<category><![CDATA[tv.asf]]></category>
		<category><![CDATA[tvants]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[vlc]]></category>
		<category><![CDATA[vlc media player]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=111</guid>
		<description><![CDATA[On Windows I was used to watching on-line television with the software Sopcast. On linux I had to spend about an hour to setup everything to correctly view P2P Tv, so I believe that this post may be useful to other people.
First of all, find and download the file sopcast-3.0.1-1.pkg.tar.gz or a more recent version [...]]]></description>
			<content:encoded><![CDATA[<p>On Windows I was used to watching on-line television with the software <em>Sopcast</em>. On linux I had to spend about an hour to setup everything to correctly view P2P Tv, so I believe that this post may be useful to other people.</p>
<p>First of all, find and download the file <a title="Sopcast Download for Linux" href="http://www.google.com/search?q=sopcast-3.0.1-1.pkg.tar.gz" target="_blank">sopcast-3.0.1-1.pkg.tar.gz</a> or a more recent version if available. Then unzip it on your disk and change directory going into its bin folder</p>
<pre>tar xfvz sopcast-3.0.1-1.pkg.tar.gz
cd sopcast-3.0.1-1.pkg/usr/bin/</pre>
<p>It&#8217;s now time to run the <em>service</em> that will connect to a p2p television stream, and will stream that video on your PC.</p>
<pre>./sp-sc-auth sop://your.favouritetv.com:3912/6002 3908 8908 &gt; /dev/null</pre>
<p>Obviously replace the URL sop://your.favouritetv.com:3912/6002 with the URL of the television you want to watch (on <a title="MyP2P.eu" href="http://www.myp2p.eu/" target="_blank">MyP2P.eu</a> there are some good channel listings) Be careful to pick an URL for Sopcast (there are many other kind of p2p softwares such as TvAnts and so on that uses different protocols).</p>
<p>Now there is a background service on your system that streams that TV on the chosen port 8908</p>
<p>The final step is to run <strong>VLC Media Player</strong> to view that stream on your monitor. This is the command:</p>
<pre>vlc http://localhost:8908/tv.asf</pre>
<p>Enjoy the show <img src='http://www.zulutown.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/04/01/watch-p2p-television-on-linux-with-sopcast-and-vlc-player/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Change your site domain or path keeping your Google PageRank and position</title>
		<link>http://www.zulutown.com/blog/2009/04/01/change-your-site-domain-or-path-keeping-your-google-pagerank-and-position/</link>
		<comments>http://www.zulutown.com/blog/2009/04/01/change-your-site-domain-or-path-keeping-your-google-pagerank-and-position/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 19:45:04 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[domain name]]></category>
		<category><![CDATA[google first position]]></category>
		<category><![CDATA[google pr]]></category>
		<category><![CDATA[http 301]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[moved]]></category>
		<category><![CDATA[pagerank]]></category>
		<category><![CDATA[permanent redirect]]></category>
		<category><![CDATA[pr]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[redirectmatch]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[relative path]]></category>
		<category><![CDATA[relocate]]></category>
		<category><![CDATA[search engine]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=105</guid>
		<description><![CDATA[When a website moves from an URL to another, the main issue for the webmaster is try to keep a good position on the Google search results (or other search engines).
Time ago I applied the SEO technique described in this article and I obtained good results.
The goal, in this example, is to move the site [...]]]></description>
			<content:encoded><![CDATA[<p>When a website moves from an URL to another, the main issue for the webmaster is try to keep a good position on the Google search results (or other search engines).<br />
Time ago I applied the <strong>SEO technique</strong> described in this article and I obtained good results.</p>
<p>The goal, in this example, is to move the site located in <code>http://www.youroldsite.com/section/</code> to the new location <code>http://www.yournewsite.com/section/</code>.</p>
<p>The trick to map everything  to the new location (without specifying every single URL) and especially to tell correctly to Google to consider that the site has moved (as described in Google FAQ) is to use the HTTP response code <em>301</em> that causes a <strong>Permanent Redirect</strong>.</p>
<p>Obviously everything inside the <code>section</code> directory must keep exactly its previous relative path. I.e. <code>http://www.youroldsite.com/section/page.html</code> have to be placed in <code>http://www.yournewsite.com/section/page.html</code>.<br />
It&#8217;s even possible, using regular expression, to map relative paths that have some differences, but a &#8220;logic&#8221; between them should exist.</p>
<p>A <code>.htaccess</code> file should be placed inside the <em>document root</em> or in the <code>section</code> subdirectory of the <strong>old</strong> website where the site is moving out<br />
The content of <code>.htaccess</code> should look like this:</p>
<pre>RedirectMatch 301 ^/section/(.*)$ http://www.yournewsite.com/section/$1</pre>
<p>Obviously if the new site has <code>section</code> moved in <code>othersection</code> the <code>.htaccess</code> should look like this:</p>
<pre>RedirectMatch 301 ^/section/(.*)$ http://www.yournewsite.com/othersection/$1</pre>
<p>And if the relocation has happened within the same domain:</p>
<pre>RedirectMatch 301 ^/section/(.*)$ /othersection/$1</pre>
<p>A test made with <code>wget</code> (a GNU tool):</p>
<pre>Connecting to www.youroldsite.com|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.yournewsite.com/section/ [following]
--2009-03-24 20:04:59--  http://www.yournewsite.com/section/
Resolving www.yournewsite.com... 127.0.0.1
Connecting to www.yournewsite.com|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK</pre>
<p>I applied the first configuration to one of my websites that was in the first position on Google for some <em>query strings</em>, because unluckily I had to move it on a new domain name.</p>
<p>The result has been very good. After 7 days I placed the <em>Redirect 301</em>, my old URL (that was the first position of Google) has been replaced by the new one. Still in the <strong>first position</strong>, and it&#8217;s still there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/04/01/change-your-site-domain-or-path-keeping-your-google-pagerank-and-position/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Tomcat6 Windows Services</title>
		<link>http://www.zulutown.com/blog/2009/03/12/creating-tomcat6-windows-services/</link>
		<comments>http://www.zulutown.com/blog/2009/03/12/creating-tomcat6-windows-services/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 21:10:49 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[catalina_home]]></category>
		<category><![CDATA[java_home]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[service.bat]]></category>
		<category><![CDATA[tomcat6]]></category>
		<category><![CDATA[tomcat_home]]></category>
		<category><![CDATA[webapps]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[windows service]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=101</guid>
		<description><![CDATA[Running the default Windows Tomcat installer a Tomcat server named Tomcat6 will be created on the Windows machine.
In the case the tomcat zipped installation file has been used, or if during the installation wizard the option for creating a Windows service hasn&#8217;t been checked, or finally, if it is required to have multiple Tomcat services [...]]]></description>
			<content:encoded><![CDATA[<p>Running the default Windows Tomcat installer a Tomcat server named <em>Tomcat6</em> will be created on the Windows machine.</p>
<p>In the case the tomcat zipped installation file has been used, or if during the installation wizard the option for creating a Windows service hasn&#8217;t been checked, or finally, if it is required to have <em>multiple Tomcat services</em> running on the server, the Tomcat features to create new services should be used.</p>
<p>Obviously it&#8217;s required to have Java installed, in this case, it&#8217;s used the JDK.</p>
<p>The following batch script will install a tomcat service named <em>YourTomcat</em> related to a <code>CATALINA_BASE</code> located in <code>c:\YourDir\YourTomcat</code>.</p>
<pre>set JAVA_HOME="c:\Program Files\Java\jdk1.6.0_12\"
set TOMCAT_HOME="c:\Program Files\Apache Software Foundation\Tomcat 6.0"
set CATALINA_BASE="c:\YourDir\YourTomcat"
call service.bat install YourTomcat</pre>
<p><code>JAVA_HOME</code> and  <code>TOMCAT_HOME</code> are obviously the places where Tomcat and Java are installed.</p>
<p>What&#8217;s the <code>CATALINA_BASE</code>? In few words, from the same Tomcat installation (located in this example in <code>c:\Program Files\Apache Software Foundation\Tomcat 6.0</code>, the <code>TOMCAT_HOME</code>) it&#8217;s possible to run more than one server instances. Each Tomcat instance has its own deployed web applications, its own logs, its own configuration and so on.</p>
<p>The <code>CATALINA_BASE</code> needs to have those directories structure:</p>
<pre>conf/
logs/
temp/
webapps/
work/</pre>
<p>In <code>conf/</code> it&#8217;s possible to copy the content of the <code>conf/</code> directory of the Tomcat installation, and obviously these files have to be customized, depending on what is required for that specific Tomcat service, i.e. the HTTP, AJP and SHUTDOWN ports, and so on.</p>
<p>In <code>logs/</code> each tomcat will write its custom <em>Catalina</em> logs or the web application specific logs (i.e. handled by Log4J).</p>
<p>In <code>temp/</code> Tomcat will obviously place temporary files.</p>
<p>In <code>webapps/</code> the web applications <code>.war</code> will be placed (and exploded).</p>
<p>in <code>work/</code> the compiled <code>.jsp</code> will be placed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/03/12/creating-tomcat6-windows-services/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Solving Tomcat OutOfMemoryError: Heap space and PermGen space</title>
		<link>http://www.zulutown.com/blog/2009/03/12/solving-tomcat-outofmemoryerror-heap-space-and-permgen-space/</link>
		<comments>http://www.zulutown.com/blog/2009/03/12/solving-tomcat-outofmemoryerror-heap-space-and-permgen-space/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 20:44:04 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[heap]]></category>
		<category><![CDATA[java options]]></category>
		<category><![CDATA[jvmmx]]></category>
		<category><![CDATA[jvmoptions]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[maximum memory pool]]></category>
		<category><![CDATA[maxpermsize]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[outofmemoryerror]]></category>
		<category><![CDATA[permgen tomcat]]></category>
		<category><![CDATA[space]]></category>
		<category><![CDATA[tomcat6]]></category>
		<category><![CDATA[tomcat6w]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=95</guid>
		<description><![CDATA[It&#8217;s quite common to run In memory problems when running some big Java EE application on a Tomcat server.
Some of the most commmon errors are like the following ones.
This is about a full Heap space:
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.OutOfMemoryError: Java heap space
This other is about the PermGen space that&#8217;s a memory area, where [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s quite common to run In <em>memory problems</em> when running some big Java EE application on a Tomcat server.<br />
Some of the most commmon errors are like the following ones.</p>
<p>This is about a full <em>Heap space</em>:</p>
<pre>SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.OutOfMemoryError: Java heap space</pre>
<p>This other is about the <em>PermGen space</em> that&#8217;s a memory area, where compiled classes (and <code>JSPs</code>) are kept, and this error might happen often if the running web application have many .java and .jsp.</p>
<pre>MemoryError: PermGen space
java.lang.OutOfMemoryError: PermGen space</pre>
<p>To increase the memory available to Tomcat, about <em>heap</em> and <em>permgen</em> the correct options are the following ones.</p>
<p>This sets the max <em>heap</em> available to Tomcat at 1Gb of memory:</p>
<pre>--JvmMx 1024</pre>
<p>This sets the max <em>permgen</em> available to Tomcat at 256Mb of memory:</p>
<pre>-XX:MaxPermSize=256m</pre>
<p>To change the Tomcat memory settings (when Tomcat is installed on Windows as <em>system service</em>), it&#8217;s required to use the command-line tool <code>tomcat6</code>. The next command changes the memory settings for the Tomcat service named <em>Tomcat6</em></p>
<pre>tomcat6 //US//Tomcat6 --JvmMx 1024 ++JvmOptions="-XX:MaxPermSize=256m"</pre>
<p>The label <code>//US//Tomcat6</code> has the meaning of <em>U</em>pdating <em>S</em>erver parameters for the service named <em>Tomcat6</em>.<br />
Obviously this command should be executed from the directory <code>C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin</code> or from wherever is the <code>bin</code> directory of your Tomcat installation. Or to make things simple, that directoy should be added to your <code>PATH</code> environment variable.</p>
<p>It&#8217;s even possible to update memory settings from a GUI frontend, or to view what happened after running the command line tool. Running the following command:</p>
<pre>tomcat6w //ES//Tomcat6</pre>
<p>a window will open showing all the parameters about the windows service <em>Tomcat6</em>.</p>
<p>It&#8217;s possible to see in this image that, after running the previous command, for setting higher memory limits, in the sections <strong>Maximum memory pool</strong> and at the end of the <strong>Java Options</strong> the new memory limits are set.</p>
<div id="attachment_96" class="wp-caption alignnone" style="width: 426px"><img class="size-full wp-image-96" title="Tomcat Memory Settings on Windows" src="http://www.zulutown.com/blog/wp-content/uploads/2009/03/configuration.png" alt="Tomcat Memory Settings on Windows" width="416" height="403" /><p class="wp-caption-text">Tomcat Memory Settings on Windows</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/03/12/solving-tomcat-outofmemoryerror-heap-space-and-permgen-space/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>SSH Tunnelling to Remote Servers, and with Local Address Binding</title>
		<link>http://www.zulutown.com/blog/2009/02/28/ssh-tunnelling-to-remote-servers-and-with-local-address-binding/</link>
		<comments>http://www.zulutown.com/blog/2009/02/28/ssh-tunnelling-to-remote-servers-and-with-local-address-binding/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 18:10:52 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[mirc]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tcp]]></category>
		<category><![CDATA[tunnel]]></category>
		<category><![CDATA[tunnelling]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=85</guid>
		<description><![CDATA[It&#8217;s often required to open different kind of connections to a server where there is available just a SSH account (or where only the port 22 is open).
Using ssh tunneling it&#8217;s easy to to access any port on the server, or even to connect to any other servers reachable from the server where the SSH [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s often required to open different kind of connections to a server where there is available just a SSH account (or where only the port <code>22</code> is open).<br />
Using <em>ssh tunneling</em> it&#8217;s easy to to access any port on the server, or even to connect to any other servers reachable from the server where the SSH account is available.</p>
<p>To access directly (i.e. with MySQL Query Browser) a MySQL service on the remote server, where the access to the port <code>3306</code> is denied, the trick is to open a SSH tunnel to the remote server, mapping an arbitrary local port the the remote port <code>3306</code>. In the following example the local port <code>5306</code> is used:</p>
<pre>ssh -L 5306:remoteserver.com:3306 remoteuser@remoteserver.com</pre>
<p>In this case, the local port <code>5306</code> is forwarded (with ssh tunnelling) to <code>remoteserver.com</code>, that attaches the tunnel on its port <code>3306</code>.<br />
When the tunnel is open, it&#8217;s only required to setup MySQL Query Browser to connect on <code>localhost:5306</code> and the connection will be magically forwarded to the remote server on its port <code>3306</code>.</p>
<div id="attachment_86" class="wp-caption alignnone" style="width: 490px"><img class="size-large wp-image-86" title="Simple ssh tunnelling of a MySQL Connection" src="http://www.zulutown.com/blog/wp-content/uploads/2009/02/simple_ssh_tunnelling-480x223.png" alt="Simple ssh tunnelling of a MySQL Connection" width="480" height="223" /><p class="wp-caption-text">Simple ssh tunnelling of a MySQL Connection</p></div>
<p>It&#8217;s even possible to set the remote side of the tunnel to be mapped not on the remote server itself, but on a <em>different host</em>.<br />
For example, if the local computer is not allowed to access IRC servers, an idea could be to use a remote server where a SSH account is available to tunnel the IRC connections.</p>
<p>Here is an example:</p>
<pre>ssh -L 8666:ircserver.org:6666 remoteuser@remoteserver.com</pre>
<p>In this case the local port <code>8666</code> is mapped on the port <code>6666</code> of the IRC server <code>ircserver.org</code>, so the local IRC client (i.e. mIRC) should be simply setup to connect on <code>localhost</code> on the port <code>8666</code>.</p>
<div id="attachment_87" class="wp-caption alignnone" style="width: 490px"><img class="size-large wp-image-87" title="SSH Tunnelling to a Different Remote Host" src="http://www.zulutown.com/blog/wp-content/uploads/2009/02/ssh_tunnelling_to_a_different_remote_host-480x142.png" alt="SSH Tunnelling to a Different Remote Host" width="480" height="142" /><p class="wp-caption-text">SSH Tunnelling to a Different Remote Host</p></div>
<p>Finally, other people in the local network might desire to use the tunnel to the remote server (in this example it&#8217;s a IRC server). If the client that opened the SSH tunnel has the IP address <code>192.168.1.1</code>, the other clients on the local network should connect to <code>192.168.1.1:8666</code> to reach the remote ircserver.org on the port 6666.</p>
<p>In this last case, it&#8217;s important to make sure that the tunnel binds to the correct local IP address.<br />
If the local client has 2 addresses: <code>127.0.0.1</code> and <code>192.168.1.1</code>, it&#8217;s useful to open the tunnel binding it on <code>192.168.1.1</code>. In this way other clients on the LAN can use the tunnel. This is the syntax:</p>
<pre>ssh -L 192.168.1.1:8666:ircserver.org:6666 remoteuser@remoteserver.com</pre>
<div id="attachment_88" class="wp-caption alignnone" style="width: 490px"><img class="size-large wp-image-88" title="SSH Tunnelling with Local Address Binding" src="http://www.zulutown.com/blog/wp-content/uploads/2009/02/ssh_tunnelling_with_address_binding-480x126.png" alt="SSH Tunnelling with Local Address Binding" width="480" height="126" /><p class="wp-caption-text">SSH Tunnelling with Local Address Binding</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/02/28/ssh-tunnelling-to-remote-servers-and-with-local-address-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java EE Load Balancing with Tomcat and Apache</title>
		<link>http://www.zulutown.com/blog/2009/02/16/java-ee-load-balancing-with-tomcat-and-apache/</link>
		<comments>http://www.zulutown.com/blog/2009/02/16/java-ee-load-balancing-with-tomcat-and-apache/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 21:16:45 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[ajp]]></category>
		<category><![CDATA[balancermember]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[connector]]></category>
		<category><![CDATA[jsessionid]]></category>
		<category><![CDATA[jvmroute]]></category>
		<category><![CDATA[load balancer]]></category>
		<category><![CDATA[load balancing]]></category>
		<category><![CDATA[mod_proxy]]></category>
		<category><![CDATA[mod_proxy_ajp]]></category>
		<category><![CDATA[mod_proxy_balancer]]></category>
		<category><![CDATA[stickysession]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=78</guid>
		<description><![CDATA[This tutorial explains how to configure an Apache HTTPD server to map a specific path on a series of load-balanced Apache Tomcat.
The first step is to define the Virtual Host in the Apache configuration files.
In this case the root directory (on file system) of the site is located in /path/to/your/site/, the name of the site [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial explains how to configure an <em>Apache HTTPD</em> server to map a specific path on a series of load-balanced <em>Apache Tomcat</em>.<br />
The first step is to define the <em>Virtual Host</em> in the Apache configuration files.<br />
In this case the root directory (on file system) of the site is located in <code>/path/to/your/site/</code>, the name of the site is <code>www.yoursite.com</code> and the path where the Tomcat servers may be reached is <code>/javaee</code>.</p>
<p>In few words, an URL like <code>http://www.yoursite.com/home.html</code> is mapped on the file <code>/path/to/your/site/home.html</code>.</p>
<p>An URL like <code>http://www.yoursite.com/javaee/hello.jsp</code> is mapped to the <code>hello.jsp</code> file contained in <code>javaee.war</code> application deployed on all the Tomcat servers defined in the <em>load balanced cluster</em>.</p>
<p>The configuration of the Apache virtual host:</p>
<pre>&lt;VirtualHost *&gt;
	ServerAdmin webmaster@localhost
	ServerName www.yoursite.com
	DocumentRoot /path/to/your/site/
	&lt;Directory /path/to/your/site/&gt;
		Options MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
	&lt;/Directory&gt;

	ErrorLog /var/log/yoursite-error.log

	LogLevel warn

	CustomLog /var/log/yoursite-access.log combined

    &lt;Proxy balancer://tomcatservers&gt;
	BalancerMember ajp://tomcatserver.yoursite.com:8009 route=tomcatA retry=60
        BalancerMember ajp://tomcatserver.yoursite.com:8010 route=tomcatB retry=60
	BalancerMember ajp://tomcatserver.yoursite.com:8011 route=tomcatC retry=60
    &lt;/Proxy&gt;

    &lt;Location /javaee&gt;
	Allow From All
        ProxyPass balancer://tomcatservers/javaee stickysession=JSESSIONID nofailover=off
    &lt;/Location&gt;

&lt;/VirtualHost&gt;</pre>
<p>The most important settings are <code>Proxy</code> and <code>Location</code>.<br />
In <code>Proxy</code> it&#8217;s defined a <em>load balancer</em> made with 3 tomcat servers and an URL is assigned to the balancer, in this case <code>balancer://tomcatservers</code>.</p>
<p>The balancer has three members, everyone with its own URL based on the <code>ajp</code> protocol. In this case Apache will connect to the Tomcat servers on their <em>AJP connectors</em> (an alternative would be to use their <em>HTTP connectors</em>).</p>
<p>The Tomcat servers run on the <code>tomcatserver.yoursite.com</code> hostname and each of them opens its own AJP connector on a different port: the first on <code>8009</code> (the default one), the second on <code>8010</code>, the third on <code>8011</code> (obviously if they run on the same hostname/IP they must bind to different ports).</p>
<p>Each Tomcat is identified by a route name: <code>tomcatA</code>, <code>tomcatB</code> and <code>tomcatC</code>. The importance of it will be explained later.</p>
<p>In the <code>Location</code> section, a specific path <code>/javaee</code> of the virtual host is mapped on the previously defined balancer <code>balancer://tomcatservers/javaee</code>. So when someone asks for <code>http://www.yoursite.com/javaee/hello.jsp</code> the virtual host will request that JSP to a randomly chosen Tomcat in the balancer members.</p>
<p>What&#8217;s the <code>stickysession</code> attribute? It&#8217;s a very useful configuration parameter used in conjunction with the <code>route</code> attributes, defined before.</p>
<p>As probably every Java EE (or Web) developer should know, while browsing on a server, it keeps trace of some data about the browsing session in a server-side <em>HttpSession</em> object. For example an ecommerce web application needs to store somewhere the information about the shopping cart of non registered users.</p>
<p>How the server can associate the remote session data with the specific navigation session? This is done through a cookie (or via a GET parameter in the URL) that gives to the server the <em>session ID</em> value.</p>
<p>In Java EE applications, the cookie name to identify the sessions is <code>JSESSIONID</code>.</p>
<p>This is closely related to the management of the load balancing between the Tomcat servers.</p>
<p>If Apache picked randomly one of the Tomcat to handle a single request and if the next request from the same user/browser was forwarded by the balancer <em>to another Tomcat</em> in that battery, things wouldn&#8217;t work correctly.</p>
<p>Each Tomcat doesn&#8217;t know anything of the existence of other Tomcat in that balancer configuration and especially a single Tomcat server cannot access the information of <em>http sessions</em> handled by another Tomcat.</p>
<p>In few words, when a Tomcat is chosen to handle the first request from a user/browser, it&#8217;s absolutely required that, to keep valid session data, the same Tomcat must be used to handle the following requests coming from that browser/user.</p>
<p>If not, on each request, the session data would be lost and simple tasks, such as building a shopping cart would result impossible.</p>
<p>So, it&#8217;s required to tell to Apache what is the session cookie name: <code>JSESSIONID</code> and which is the identifier of the routes to each single tomcat Server: <code>tomcatA</code>, <code>tomcatB</code>, <code>tomcatC</code>.</p>
<p>In this way, Apache will append to the end of the cookie value the information about the route to the specific Tomcat.</p>
<div id="attachment_83" class="wp-caption aligncenter" style="width: 490px"><img class="size-large wp-image-83" title="Java EE Tomcat Load Balancing" src="http://www.zulutown.com/blog/wp-content/uploads/2009/02/javaee-tomcat-load-balancing-480x320.png" alt="Java EE Tomcat Load Balancing" width="480" height="320" /><p class="wp-caption-text">Java EE Tomcat Load Balancing</p></div>
<p>Finally, the last thing to set-up Apache, is obviously to add to it the  modules required by the previous configuration:</p>
<ul>
<li>proxy</li>
<li>proxy_balancer</li>
<li>proxy_ajp</li>
</ul>
<p>About Tomcat configuration, there are just few changes to apply to the default configuration, in the <code>Engine</code> section it&#8217;s required to add the <code>jvmRoute</code> attribute.</p>
<pre>&lt;Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatA"&gt;</pre>
<p>This is related to the <code>route</code> parameter defined in the Apache load balancer. So, <code>tomcatA</code> should be set in the configuration of the first Tomcat server, <code>tomcatB</code> in the second and <code>tomcatC</code> in the third one.</p>
<p>Then, the port where <em>AJP connector</em> listens, has to be set accordingly to the apache configuration, so <code>8009</code>, <code>8010</code>, <code>8011</code> respectively on the first, second and third Tomcat.</p>
<p>The following is the the configuration of the <em>AJP connector</em>:</p>
<pre>&lt;Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /&gt;</pre>
<p>It&#8217;s not directly related to the setup of the load-balancer, but since they run on the same host, each Tomcat should have its own set of ports.</p>
<p>To prevent any conflict you should change the following settings on the second and third servers: <code>Server port="8005"</code> and <code>Connector port="8080"</code>.</p>
<p>I hope this tutorial has given a complete overview about every step required to setup <em>Apache</em> and <em>Tomcat</em> to create a simple load-balanced cluster.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/02/16/java-ee-load-balancing-with-tomcat-and-apache/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Executing Commands and Scripts Remotely with ssh</title>
		<link>http://www.zulutown.com/blog/2009/02/13/executing-commands-and-scripts-remotely-with-ssh/</link>
		<comments>http://www.zulutown.com/blog/2009/02/13/executing-commands-and-scripts-remotely-with-ssh/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 22:17:11 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[remotely]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=76</guid>
		<description><![CDATA[Often it&#8217;s required to execute on a remote server a command or a whole bash script.
Not everyone knows that through ssh it&#8217;s possible to execute this task.
Here&#8217;s the ssh syntax:
usage: ssh [-1246AaCfgKkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-e escape_char] [-F configfile]
    [...]]]></description>
			<content:encoded><![CDATA[<p>Often it&#8217;s required to execute on a remote server a command or a whole bash script.<br />
Not everyone knows that through <code>ssh</code> it&#8217;s possible to execute this task.</p>
<p>Here&#8217;s the ssh syntax:</p>
<pre>usage: ssh [-1246AaCfgKkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-e escape_char] [-F configfile]
           [-i identity_file] [-L [bind_address:]port:host:hostport]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-R [bind_address:]port:host:hostport] [-S ctl_path]
           [-w local_tun[:remote_tun]] [user@]hostname [command]</pre>
<p>In the following example , the <code>ls</code> command is run on the remote server.</p>
<pre>ssh remoteuser@remoteserver.com ls</pre>
<p>To run a local script on the remote server, it&#8217;s required to upload it (through <code>scp</code>), set it as executable and finally run it.</p>
<p>The related example:</p>
<pre>scp myscript.sh remoteuser@remoteserver.com:/remotedir/myscript.sh
ssh remoteuser@remoteserver.com "chmod +x /remotedir/myscript.sh"
ssh remoteuser@remoteserver.com /remotedir/myscript.sh</pre>
<p>Of course it&#8217;s required to type the password after each command (or to use a identity key file)</p>
<p>Looking through the <code>ssh</code> options it&#8217;s possible to find many other feature offered by this common command.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/02/13/executing-commands-and-scripts-remotely-with-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copying Files between Clients and Servers over ssh using scp</title>
		<link>http://www.zulutown.com/blog/2009/02/07/copying-files-between-clients-and-servers-over-ssh-using-scp/</link>
		<comments>http://www.zulutown.com/blog/2009/02/07/copying-files-between-clients-and-servers-over-ssh-using-scp/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 12:52:58 +0000</pubDate>
		<dc:creator>Zulutown Webmaster</dc:creator>
				<category><![CDATA[Linux / Unix]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[copying]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[recursively]]></category>
		<category><![CDATA[remote]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[transfer]]></category>

		<guid isPermaLink="false">http://www.zulutown.com/blog/?p=73</guid>
		<description><![CDATA[It&#8217;s quite common to need to upload or download file between one or more servers and the local computer.
If it&#8217;s available a ssh access on the servers, using scp to transfer file from and to the server could be a very good option.
Here&#8217;s its syntax:
usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
   [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s quite common to need to upload or download file between one or more servers and the local computer.</p>
<p>If it&#8217;s available a <em>ssh access</em> on the servers, using <code>scp</code> to transfer file from and to the server could be a very good option.</p>
<p>Here&#8217;s its syntax:</p>
<pre>usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2</pre>
<p>A very simple example:</p>
<pre>scp localfilename.txt remoteuser@www.remotehost.com:remotefilename.txt</pre>
<p>The previous example copies <code>localfilename.txt</code> from the local directory to the server <code>www.remotehost.com</code> using <code>remoteuser</code> as the ssh account to authenticate on the remote server. On the remote server the transferred file will be stored as <code>remotefilename.txt</code> in the default login directory of <code>remoteuser</code>.</p>
<p>Copying file from and to specific directories:</p>
<pre>scp /localdir/localfilename.txt remoteuser@www.remotehost.com:/remotedir/remotefilename.txt</pre>
<p>Compared to the previous example, in this case, the file is taken from <code>/localdir/localfilename.txt</code> and stored remotely on <code>/remotedir/remotefilename.txt</code>.<br />
Obviously <code>remoteuser</code> should have write permission on the remote directory where the file is going to be written.</p>
<p>In the next case, the authentication is made through a keyfile, this is the syntax:</p>
<pre>scp -i keyfile /localdir/localfilename.txt remoteuser@www.remotehost.com:/remotedir/remotefilename.txt</pre>
<p>In this case to login as <code>remoteuser</code> there will not be a prompt for password, but <code>keyfile</code> is used as identity file.</p>
<p>It&#8217;s even possible to copy directly files from one server to another</p>
<pre>scp firstremoteuser@www.firstserver.com:/filename.txt anotherremoteuser@www.anotherserver.com:/remotedir/remotefilename.txt</pre>
<p>Finally one of the best features is to copy recursively directory trees to the remote server:</p>
<pre>scp -r /localdirectory remoteuser@www.remoteserver.com:/remotedirectory</pre>
<p>In this case, the whole content of localdirectory is recursively copied into remotedirectory. This can be very useful for moving quickly website structures.<br />
I hope you&#8217;ve found some useful information in this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zulutown.com/blog/2009/02/07/copying-files-between-clients-and-servers-over-ssh-using-scp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
