<?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>GimmeSoda &#187; Programming</title>
	<atom:link href="http://www.gimmesoda.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gimmesoda.com</link>
	<description>The Blog of a Programmer</description>
	<lastBuildDate>Mon, 26 Jul 2010 07:54:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Generating Thumbnails from FLV using FFMPEG</title>
		<link>http://www.gimmesoda.com/generating-thumbnails-from-flv-using-ffmpeg/</link>
		<comments>http://www.gimmesoda.com/generating-thumbnails-from-flv-using-ffmpeg/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 10:15:14 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=184</guid>
		<description><![CDATA[I had to make some modifications to a zenGallery system which was going to hold a lot of flash video files and I was too lazy to create a thumbnail for each image so for awhile it had the default thumbnail. After a few, &#8220;what&#8217;s with the thumbnails?&#8221; I decided to write a script that]]></description>
			<content:encoded><![CDATA[<p>I had to make some modifications to a zenGallery system which was going to hold a lot of flash video files and I was too lazy to create a thumbnail for each image so for awhile it had the default thumbnail.</p>
<p>After a few, &#8220;what&#8217;s with the thumbnails?&#8221; I decided to write a script that executed ffmpeg to create a thumbnail for each video (from the frame 10 seconds into the video) and write out a jpg image.</p>
<p>The filename currently just replaces .flv with .jpg and my settings for the call are pretty generic. If anyone has questions about this feel free to ask.</p>
<p>Grab the .phps file from here: <a href="http://files.gimmesoda.com/code_samples/generate_thumbs.phps">Generate Thumbnails from FLV files using FFMPEG</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/generating-thumbnails-from-flv-using-ffmpeg/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>-bash: /bin/rm: Argument list too long (AKA: Too Many Files)</title>
		<link>http://www.gimmesoda.com/bash-binrm-argument-list-too-long-aka-too-many-files/</link>
		<comments>http://www.gimmesoda.com/bash-binrm-argument-list-too-long-aka-too-many-files/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 21:15:17 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[Linux Command Line]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/2008/02/21/bash-binrm-argument-list-too-long-aka-too-many-files/</guid>
		<description><![CDATA[find /path/to/directory/ -exec rm {} \; So apparently that command is magical! Alright, so it&#8217;s not magical but it was able to delete over 200,000 spam messages from a users Maildir/ when the rm command failed. &#8220;-bash: /bin/rm: Argument list too long&#8221;, it complained! So asking around I found out about that beauty of a]]></description>
			<content:encoded><![CDATA[<p>find /path/to/directory/ -exec rm {} \;</p>
<p>So apparently that command is magical! Alright, so it&#8217;s not magical but it was able to delete over 200,000 spam messages from a users Maildir/ when the rm command failed. &#8220;-bash: /bin/rm: Argument list too long&#8221;, it complained! So asking around I found out about that beauty of a command and how rm can only take a certain amount of arguments before failing.</p>
<p>Nice to know, as my journey of learning more about Debian Linux (and Linux in general) continues.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/bash-binrm-argument-list-too-long-aka-too-many-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MD5 with Dynamic Salt Class</title>
		<link>http://www.gimmesoda.com/md5-with-dynamic-salt-class/</link>
		<comments>http://www.gimmesoda.com/md5-with-dynamic-salt-class/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 03:28:54 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=46</guid>
		<description><![CDATA[Remember my post about MD5 Hashing and Salt? Well I&#8217;ve taken some time to develop a PHP class which helps very easily implement dynamic salt when using MD5. This class can be easily expanded or modified to use a different hash function. Take a look at it and let me know if it becomes useful]]></description>
			<content:encoded><![CDATA[<p>Remember my post about <a target="_blank" href="http://juanjose.blackfalconsolutions.com/2007/09/13/md5-hashing-and-salt/" title="MD5 Hashing and Salt">MD5 Hashing and Salt</a>? Well I&#8217;ve taken some time to develop a PHP class which helps very easily implement dynamic salt when using MD5. This class can be easily expanded or modified to use a different hash function. Take a look at it and let me know if it becomes useful to anyone!</p>
<p>You can <a href="http://juanjose.blackfalconsolutions.com/PasswordWithSalt.class.zip" title="MD5 with Dynamic Salt">download the PasswordWithSalt.class.php file here</a>. Also I setup a <a target="_blank" href="http://juanjose.blackfalconsolutions.com/PasswordWithSalt_Test.php">VERY simple demo</a> of how this works. I&#8217;m still working on developing this but comments and advice will definately be useful here.</p>
<p> The following is the rough text and instructions I&#8217;ve written for my &#8220;readme.txt&#8221; file.</p>
<p><font size="2"></p>
<blockquote>
<p align="left">The only thing you need to do in order to properly configure this class is set the location you want to store your salts at. For example in the class set $storageLocation = &#8220;/home/user/salts/&#8221;; and give permissions for your server to write to that folder  (777 will work). I recommend the folder to be one outside your normal webroot.</p>
<p align="left">The following demonstrates how to store salt for your user, then generate the hash using those salts. Don&#8217;t forget to store the final hash so you can compare against it later!</p>
<p align="left">&lt;?php<br />
require(&#8220;PasswordWithSalt.class.php&#8221;);</p>
<p align="left">//Init the class<br />
$SaltPlease = new PasswordWithSalt();</p>
<p align="left">//Store generated salts for user &#8220;admin&#8221;<br />
$SaltPlease-&gt;storeSalt(&#8220;admin&#8221;);</p>
<p align="left">//Get hash for user admin, password is &#8220;password&#8221;<br />
$hash = $SaltPlease-&gt;createHash(&#8220;admin&#8221;, &#8220;password&#8221;);<br />
?&gt;</p>
<p align="left">&nbsp;</p>
<p align="left">The following demonstrates how to duplicate the hash for a user who already has salt. $dbhash should be filled with the hash you have stored before.</p>
<p align="left">&lt;?php<br />
require(&#8220;PasswordWithSalt.class.php&#8221;);</p>
<p align="left">//Init the class<br />
$SaltPlease = new PasswordWithSalt();</p>
<p align="left">//Get hash for user admin, password is &#8220;password&#8221;<br />
$hash = $SaltPlease-&gt;createHash(&#8220;admin&#8221;, &#8220;password&#8221;);</p>
<p align="left">//Check to see if the generated hash match.<br />
if($dbhash == $hash) {<br />
echo &#8220;Password Hashes Match.&#8221;;<br />
} else {<br />
echo &#8220;Password Hashes DO NOT Match&#8221;;<br />
}<br />
?&gt;</p></blockquote>
<p></font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/md5-with-dynamic-salt-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MD5 Hashing and Salt</title>
		<link>http://www.gimmesoda.com/md5-hashing-and-salt/</link>
		<comments>http://www.gimmesoda.com/md5-hashing-and-salt/#comments</comments>
		<pubDate>Thu, 13 Sep 2007 18:47:56 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=38</guid>
		<description><![CDATA[I just read a great post by Marcel Oelke who runs http://md5.rednoize.com/. He&#8217;s got a great way to access his webservice and then check if a user&#8217;s password is insecure. Even if you are using MD5 before storing the password, I certianly hope people aren&#8217;t storing passwords in cleartext, it may not be secure. I]]></description>
			<content:encoded><![CDATA[<p>I just read a great post by Marcel Oelke who runs <a href="http://md5.rednoize.com/">http://md5.rednoize.com/</a>. He&#8217;s got a great way to access his webservice and then check if a user&#8217;s password is insecure. Even if you are using MD5 before storing the password, I certianly hope people aren&#8217;t storing passwords in cleartext, it may not be secure.<span id="more-38"></span></p>
<p>I know many people don&#8217;t add some salt before storing the password and MD5.rednoize.com really is the perfect example as to why you should be salting all passwords! Even if you have a single sitewide salt - prepending it to a user&#8217;s password before creating the hash is a powerful way to prevent the use of a database like the one which runs MD5.rednoize.com matching against your database. So basically in PHP:</p>
<p>$salt = &#8220;ThisSuperLongStringWillProtectMyUsersAgainstInsecurePasswords&#8221;;<br />
$userpass = $_POST['pass'];<br />
$md5pass = md5($salt . $userpass);</p>
<p>When your user then attempts to login you&#8217;ll duplicate the same process. I personally would keep the $salt in a file outside the normal webroot.</p>
<p>Now the chances of a site having the matching hash to your users password &#8211; even if the pass is &#8221;word&#8221; is MUCH less likely. I hope this explains what it means to salt your passwords.</p>
<p>You can read Marcel&#8217;s post and learn how to call his webservice here:<br />
<a href="http://pure.rednoize.com/2005/11/10/checking-password-strength-using-md5rednoizecom-and-ajax/">http://pure.rednoize.com/2005/11/10/checking-password-strength-using-md5rednoizecom-and-ajax/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/md5-hashing-and-salt/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Image Resizing Using PHP and the GD library</title>
		<link>http://www.gimmesoda.com/image-resizing-using-php-and-the-gd-library/</link>
		<comments>http://www.gimmesoda.com/image-resizing-using-php-and-the-gd-library/#comments</comments>
		<pubDate>Sun, 26 Nov 2006 10:48:00 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux Command Line]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=15</guid>
		<description><![CDATA[I&#8217;m developing a new system core, can&#8217;t really say what it&#8217;s about but I&#8217;m having some fun doing it. Coding it is interesting, I&#8217;m getting to pull out and update some of my php code. Below is some code for image resizing, I use config files to set some default information like directories to save]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m developing a new system core, can&#8217;t really say what it&#8217;s about but I&#8217;m having some fun doing it. Coding it is interesting, I&#8217;m getting to pull out and update some of my php code. Below is some code for image resizing, I use config files to set some default information like directories to save to and max width/height requirements. Also the entire system uses language files so I don&#8217;t output the text directly either, except for what I&#8217;m going to remove which is the uploaded file information.</p>
<p>Resize JPG images using the GD library and PHP.</p>
<blockquote><p>function get_image_information($key) {<br /> global $thumbnail_dest, $image_dest, $thumb_max_height, $thumb_max_width, $image_max_height, $image_max_width;<br /> $filename = $_FILES[$key]["name"];<br /> $file_type = $_FILES[$key]["type"];<br /> $file_tmpname = $_FILES[$key]["tmp_name"];<br /> $file_error = $_FILES[$key]["error"];<br /> $file_size = $_FILES[$key]["size"];</p>
<p> if($file_error == 0 &&amp; $file_size > 0) {<br />  if($file_type == &#8220;image/pjpeg&#8221;  $file_type == &#8220;image/jpeg&#8221;  $file_type == &#8220;image/jpg&#8221;) {<br />   $image_name = md5(time() . rand(1001,10000)) . &#8220;.jpg&#8221;;<br />   $thumb_dest = $thumbnail_dest . $image_name;<br />   $image_dest = $image_dest . $image_name;<br />   create_image($file_tmpname, $thumb_max_height, $thumb_max_width, $thumb_dest);<br />   create_image($file_tmpname, $image_max_height, $image_max_width, $image_dest);<br />   return &#8220;thumbs/&#8221; . $image_name;<br />  } else {<br />   $success .= file_upload_success_1 . $filename . file_upload_success_2 . &#8220;<br />&#8220;;<br />   $success .= &#8220;We can only accept jpg uploads. Upload Failed.&#8221;;<br />   return $success;<br />  }<br /> } else {<br />  if($file_error == 1) {<br />   echo $file_upload_fail_1;<br />  } elseif($file_error == 2) {<br />   echo $file_upload_fail_2;<br />  } elseif($file_error == 3) {<br />   echo $file_upload_fail_3;<br />  } elseif($file_error == 4) {<br />   echo $file_upload_fail_4;<br />  } elseif($file_error == 6) {<br />   echo $file_upload_fail_6;<br />  }<br />  return false;<br /> }<br />}<br />function create_image($image, $max_width, $max_height, $dest) {<br /> $image = imagecreatefromjpeg($image);<br /> if ($image === false) {<br />  die (&#8216;Unable to open image&#8217;);<br /> }</p>
<p> $width = imagesx($image);<br /> $height = imagesy($image);</p>
<p> if($width < $max_width &#038;&#038; $height < $max_height) {<br />  $new_width = $width;<br />  $new_height = $height;<br /> } else {<br />  $scale = min($max_width/$width, $max_height/$height);<br />  $new_width = floor($scale * $width);<br />  $new_height = floor($scale * $height);<br /> }</p>
<p> $image_resized = imagecreatetruecolor($new_width, $new_height);<br /> imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);<br /> imagejpeg($image_resized, $dest, 90);<br />}</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/image-resizing-using-php-and-the-gd-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The XML Document Object Model</title>
		<link>http://www.gimmesoda.com/the-xml-document-object-model/</link>
		<comments>http://www.gimmesoda.com/the-xml-document-object-model/#comments</comments>
		<pubDate>Sat, 15 Jul 2006 16:24:00 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=11</guid>
		<description><![CDATA[I&#8217;m writing a bunch of functions that communicate with Amazon using classic asp, it requires me to learn much more about the XMLDOM, so that I don&#8217;t manually parse through every XML file. For anyone else who is interested in the XMLDOM I recommend the article, &#8220;XML&#8220;, over at Dev Articles who, by the way,]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing a bunch of functions that communicate with Amazon using classic asp, it requires me to learn much more about the XMLDOM, so that I don&#8217;t manually parse through every XML file. For anyone else who is interested in the XMLDOM I recommend the article, &#8220;<a href="http://www.devarticles.com/c/a/XML/Roaming-through-XMLDOM-An-AJAX-Prerequisite/">XML</a>&#8220;, over at <a href="http://www.devarticles.com/">Dev Articles</a> who, by the way, tend to produce many many very helpful and articulate articles written in a manner most people can either understand or learn to understand.</p>
<p>JJ</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/the-xml-document-object-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Do a Search Through Folders – Two Levels Deep</title>
		<link>http://www.gimmesoda.com/how-to-do-a-search-through-folders-two-levels-deep/</link>
		<comments>http://www.gimmesoda.com/how-to-do-a-search-through-folders-two-levels-deep/#comments</comments>
		<pubDate>Sat, 15 Jul 2006 02:24:00 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=10</guid>
		<description><![CDATA[I used the following code to search through my &#8220;galleries&#8221; folder and search for images through every folder inside galleries sub-folders. Huh? I used each folder inside of galleries as the &#8220;category&#8221; for each set of images. What it ended up doing was this. Each time I wanted to create a new category I would]]></description>
			<content:encoded><![CDATA[<p>I used the following code to search through my &#8220;galleries&#8221; folder and search for images through every folder inside galleries sub-folders.</p>
<p><span style="font-weight: bold">Huh?</span></p>
<p>I used each folder inside of galleries as the &#8220;category&#8221; for each set of images. What it ended up doing was this. Each time I wanted to create a new category I would just make a new folder inside of &#8220;galleries&#8221;, each time I wanted a new album I&#8217;d put another folder inside each category folder. For example I could have a folder structure as follows:<br />
/galleries<br />
&#8212;/wedding<br />
&#8212;&#8212;-/getting_ready<br />
&#8212;&#8212;-/court_house<br />
&#8212;&#8212;-/reception<br />
&#8212;/first_home<br />
&#8212;&#8212;-/before<br />
&#8212;&#8212;-/after</p>
<p>As you can see my categories are under galleries and they are called &#8220;wedding&#8221; and &#8220;first_home&#8221;. My galleries are called &#8220;getting_ready&#8221;, &#8220;court_house&#8221;, &#8220;reception&#8221;, &#8220;before&#8221; and &#8220;after&#8221;.</p>
<p><span style="font-weight: bold">Oh I see!</span></p>
<p>I&#8217;m not going to be releasing the code to the entire program because an ex co-worker of mine and I plan on selling a gallery solution based on this, but here is the code for the folder searching! It is possible to modify this to do a full recursive search, I&#8217;ve done it before. Try creating another folder search function, while building the folder path you are passing into the functions as you go. It&#8217;s possible to build a recursive output that will show every file in an entire site directory, if you set root_folder = &#8220;/&#8221;</p>
<p><span style="font-weight: bold">The Code</span></p>
<p>root_folder = &#8220;/galleries/&#8221;<br />
SearchFolders root_folder</p>
<p>Sub SearchFolders(root_folder)<br />
set FileSysObj=CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />
strFullPath = server.mappath(root_folder)<br />
set fldr=FileSysObj.GetFolder(strFullPath)<br />
set FolderList = fldr.SubFolders<br />
For Each FolderIndex in FolderList<br />
Response.Write(FolderIndex.name &amp; &#8221;<br />
&#8220;)<br />
Next<br />
set FileList = fldr.Files<br />
For Each FileIndex in FileList<br />
Response.Write(FileIndex.name &amp; &#8221;<br />
&#8220;)<br />
Next<br />
End Sub</p>
<p>Sub DisplaySubFolders(root_folder, parent_folder)<br />
set FileSysObj=CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />
strFullPath = server.mappath(root_folder)<br />
set fldr=FileSysObj.GetFolder(strFullPath)<br />
set FolderList = fldr.SubFolders<br />
For Each FolderIndex in FolderList<br />
Response.Write(FolderIndex.name &amp; &#8221;<br />
&#8220;)<br />
Next<br />
set FileList = fldr.Files<br />
For Each FileIndex in FileList<br />
Response.Write(FileIndex.name &amp; &#8221;<br />
&#8220;)<br />
Next<br />
End Sub</p>
<p>Enjoy,<br />
JJ</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/how-to-do-a-search-through-folders-two-levels-deep/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>API’s Gone Wild</title>
		<link>http://www.gimmesoda.com/apis-gone-wild/</link>
		<comments>http://www.gimmesoda.com/apis-gone-wild/#comments</comments>
		<pubDate>Fri, 14 Jul 2006 00:19:00 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=9</guid>
		<description><![CDATA[Google, Amazon, Ebay For all those developers interested in making some seriously interesting or possibly revenue generating programs the google, amazon, and ebay api&#8217;s may be a good place to start. I&#8217;ve used them in the past always to make something small for a client. Now it&#8217;s my turn, and although the programs I would]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold;">Google, Amazon, Ebay</span></p>
<p>For all those developers interested in making some seriously interesting or possibly revenue generating programs the google, amazon, and ebay api&#8217;s may be a good place to start. I&#8217;ve used them in the past always to make something small for a client.</p>
<p>Now it&#8217;s my turn, and although the programs I would like to make may be small they&#8217;ll be a great learning experience and my own! It&#8217;s just that special little feeling of accomplishment when that first XML transaction goes through and you recieve something other than an error code! Ah, yes that&#8217;s a good feeling indeed!</p>
<p>So yeah I went a little overboard today and signed up for every major API at the three.<br />
If you&#8217;re interested take a look!<br />
<a href="http://www.google.com/apis/maps/">Google Maps API</a> (This one is just fun.)<br />
<a href="http://code.google.com/apis/ajaxsearch/">Google Ajax Search API</a> (Might be interesting.)<br />
<a href="http://www.google.com/apis/adwords/">Google Adwords API</a> (Maybe make some money off this.)<br />
<a href="http://code.google.com/apis/checkout/">Google Checkout API</a> (Sign up for sandbox if developing. Looks great in my opinion.)<br />
<a href="http://www.amazon.com/b/104-6354470-1627946?ie=UTF8&amp;node=3435361">Amazon Web Services</a> (You can make some interesting things out of this!)<br />
<a href="http://developer.ebay.com/common/api">Ebay API</a> (Hmmm webservices with ebay&#8230; definately could build something interesting!)</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/apis-gone-wild/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating FTP</title>
		<link>http://www.gimmesoda.com/automating-ftp/</link>
		<comments>http://www.gimmesoda.com/automating-ftp/#comments</comments>
		<pubDate>Thu, 13 Jul 2006 06:53:00 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows Command Line]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=7</guid>
		<description><![CDATA[The Problem I need to automate an FTP transaction. No big deal right? I need to automate my FTP transaction from inside a .net console program, then execute the same program with multiple instances that process each downloaded file. Shell()I&#8217;m really loving this command. It&#8217;s nothing new really but for some reason or another it]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold;">The Problem</span></p>
<p>I need to automate an FTP transaction. No big deal right? I need to automate my FTP transaction from inside a .net console program, then execute the same program with multiple instances that process each downloaded file.</p>
<p><span style="font-weight: bold;">Shell()</span><span style="font-weight: bold;">I&#8217;m really loving this command. It&#8217;s nothing new really but for some reason or another it tends not to be common knowledge. I suppose the land of DOS and those wonderful black and white (although sometimes colorful) programs has been left slowly behind by most newer developers.</span></p>
<p><span style="font-weight: bold;">The Answer</span></p>
<p>Technically I already told you the answer to my problem, but I didn&#8217;t exactly explain it in full. Here is the code, I&#8217;ll explain it more later.</p>
<blockquote><p>Shell(&#8220;ftp -s:ftp.script&#8221;)</p></blockquote>
<p>Isn&#8217;t that just great!? It turns out that the normal MS-DOS FTP command already has a basic scripting control in it. So using Shell() to execute ftp, which is in my system PATH, and passing the -s:filename argument into it the ftp. The program then opens your script and uses it to answer each of the prompts it would normally give. My FTP script is very simple and here is a copy.</p>
<blockquote><p>prompt<br />
open ftp.myserver.com<br />
USERNAME<br />
PASSWORD<br />
cd directory<br />
mget *.txt<br />
bye</p></blockquote>
<p>Here is a quick breakdown of the script.<br />
prompt: is an FTP program command which disables or enables the interactive prompt<br />
I want this disabled so that I can automatically overwrite files, and accept file downloads.<br />
open: standard open command, set the server IP or server name here<br />
USERNAME: the server always asks for a username &#8211; set it here by replacing USERNAME with the real username<br />
PASSWORD: replace it with your password<br />
Repeat your password<br />
cd: change directory &#8211; usage: cd /directory/to/work/in/<br />
mget: multiple get &#8211; wildcards can be used for filename and extension<br />
Example:<br />
the*developer.txt would match:<br />
thecrazydeveloper.txt, themaddeveloper.txt, and so on.<br />
*.txt matches all files with .txt in the filename<br />
*.* matches all files in the directory<br />
bye: logs you out of the server</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/automating-ftp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Basic.net Console Applications</title>
		<link>http://www.gimmesoda.com/visual-basicnet-console-applications/</link>
		<comments>http://www.gimmesoda.com/visual-basicnet-console-applications/#comments</comments>
		<pubDate>Tue, 11 Jul 2006 18:03:00 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=6</guid>
		<description><![CDATA[Microsoft Adds Improved Support for Console Apps in .Net When I learned that .net had improved support for console apps I became immediately excited about the whole thing. I love data processing, parsing, and conversion; I&#8217;m a geek in all every possible sense of the word. It can be a true mental challenge to convert]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold">Microsoft Adds Improved Support for Console Apps in .Net</span></p>
<p>When I learned that .net had improved support for console apps I became immediately excited about the whole thing. I love data processing, parsing, and conversion; I&#8217;m a geek in all every possible sense of the word. It can be a true mental challenge to convert something one company believes to be a complete and sensible data format to what another company believes to be the same.</p>
<p>In this past week I came across the need to build a program which will be capable of automation and quickly converting one companies file format to another.</p>
<p><span style="font-weight: bold">O&#8217; The Possibilities</span></p>
<p>Since I am mostly a web based developer my immediate thought was VBScript (Classic ASP) hosted on an IIS capable server on which we would have a batch calling ftp to download the files which needed to be parsed, saving them to a specific folder, and executing the .asp script.</p>
<p>Unfortunately the server which would be running the program (decided on by the client company) does not run IIS, so there goes that idea. Another idea was to run it as a .vbs script using windows internal scripting. I&#8217;ve always had a bad feeling about using those files and decided that would not be a grand idea. Out of a gut feeling I scratched that idea.</p>
<p><span style="font-weight: bold">What about .net?</span></p>
<p>I had worked with VB.net only a few times before and thought it would be easy enough to do the job with. What about automation? Having a form without need of human intervention would allow the program to run by itself BUT why do I even need that? It would make the program larger and that is completely unnecessary. The next thought that came to my mind was, &#8220;I miss DOS.&#8221;</p>
<p><span style="font-weight: bold">DOS and Console Applications!</span></p>
<p>Most of you past the age of 20 or so should remember console apps. Those DOS console windows, the constant use of &#8220;cmd&#8221; or &#8220;command&#8221; from your start &#8212;&gt; run menu, and (for those of us who like to play those old dos games) <a href="http://www.freedos.org/">free dos</a> or <a href="http://dosbox.sourceforge.net/news.php?show_news=1">DOSBox</a>! Either way, those wonderful apps didn&#8217;t just become useless or out of style with the advent of easily built apps with nifty GUI&#8217;s!</p>
<p>Console apps are great for processing and well automating processes! Which is how I am using my newest little application.</p>
<p><span style="font-weight: bold">How to Write Console Apps with .Net 2003</span><span style="font-weight: bold"><span style="font-weight: bold"></span>Okay first off, I know .net 2005 is out. I&#8217;m currently using .net visual studio 2003, and although the process should be similar in 2005, perhaps even better; I&#8217;m using 2003 and that&#8217;s what you&#8217;ll learn here. That is, until I get upgraded.</span><span style="font-weight: bold">So open up your .net enviroment.</p>
<p></span>Create a new project selecting Visual Basic Projects (left hand side), and Console Application (right hand side). Name your application and have it save to whatever location you&#8217;d like.</p>
<p><span style="font-weight: bold"><span style="font-weight: bold"></span>Module1.vb</span><span style="font-weight: bold">If you are anything like me you&#8217;ll love the fact that the first thing you see after creating this new application is a code window! None of the GUI or form clutter. Straight to the heart of the matter! Now unless your application is completely static, as in it always processes the same file(s), you&#8217;ll need your program to handle arguments. In my case it needs to handle 1 argument and that would be the file name of the text file to be parsed.</span><span style="font-weight: bold"><span style="font-weight: bold">Handling Arguments<br />
</span></p>
<p></span></p>
<blockquote><p>Sub Main()<br />
Main(System.Environment.GetCommandLineArgs())<br />
End Sub</p></blockquote>
<p>Wonderful little piece of code! Since this is the first function executed in your program all it will do is collect the arguments from the command line and pass them into a private sub also called Main in your application, in which you can check for the correct arguments and actually do your processing! Here is a basic example:</p>
<blockquote><p>Private Sub Main(ByVal arguments() As String)<br />
If arguments Is Nothing OrElse arguments.Length &lt;&gt; 2 Then<br />
Console.WriteLine(&#8220;You must enter atleast one argument for this program to execute!&#8221;)<br />
Else<br />
System.Console.WriteLine(&#8220;&#8211;==Welcome to My Console Application==&#8211;&#8221;)<br />
If (arguments(1) = &#8220;-V&#8221;) Then<br />
System.Console.WriteLine(&#8220;&#8211;==Written by JuanJose H. Galvez==&#8211;&#8221;)<br />
Exit Sub<br />
Else<br />
Dim user_name<br />
System.Console.WriteLine(&#8220;What is your name?&#8221;)<br />
user_name = System.Console.ReadLine()<br />
System.Console.WriteLine(&#8220;Your name is: &#8221; &amp; user_name)<br />
End If<br />
End If<br />
End Sub</p></blockquote>
<p>From the above example you should be able to figure out how to initiate variables, set user input into a program usable variable, how to write out strings to the screen! Also, you&#8217;ll either run into this or figure it out yourself but arguments(0) is actually equal to the filename of the program, which is why the argument(1) is used when seeking the input argument used to run the program.</p>
<p>Example: &#8220;ConsoleApplication1.exe&#8221; -V<br />
Example: &#8220;ConsoleApplication1.exe&#8221; AnythingCanGoHere</p>
<p><span style="font-weight: bold">This is obviously a useless program!<br />
You&#8217;ve wasted my time!</span><span style="font-weight: bold">Actually, this little program was indeed a useless example, in that it does nothing of use; thus the use of the term useless; but it does end up teaching someone who is new to console applications how to get started. It also teaches the basic concepts behind arguments and how to do basic input output operations between the program and the end user.</span><span style="font-weight: bold">And you wasted your own time reading this! I wasted time writing! :)<br />
<span style="font-weight: bold"></span></p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/visual-basicnet-console-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
