<?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>Christian Schenk&#187; ftp</title>
	<atom:link href="http://www.christianschenk.org/blog/tag/ftp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christianschenk.org</link>
	<description>Writing about my experiences with technology and all different kinds of projects and experiments</description>
	<lastBuildDate>Sun, 29 Aug 2010 09:08:16 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Automate FTP sessions with Windows</title>
		<link>http://www.christianschenk.org/blog/automate-ftp-sessions-windows/</link>
		<comments>http://www.christianschenk.org/blog/automate-ftp-sessions-windows/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 07:55:44 +0000</pubDate>
		<dc:creator>Christian Schenk</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[at]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.christianschenk.org/?p=308</guid>
		<description><![CDATA[You&#8217;d like to upload some files from a PC running Windows via FTP to another server every now and then? It&#8217;s as easy as:

saving the appropriate FTP commands in a text file
using Windows&#8217; built-in ftp command along with the text file
adding a task to the at scheduler.

Let&#8217;s have a look at this.

The upload script
First we&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;d like to upload some files from a PC running Windows via FTP to another server every now and then? It&#8217;s as easy as:</p>
<ul>
<li>saving the appropriate FTP commands in a text file</li>
<li>using Windows&#8217; built-in <code>ftp</code> command along with the text file</li>
<li>adding a task to the <code>at</code> scheduler.</li>
</ul>
<p>Let&#8217;s have a look at this.</p>
<p><span id="more-308"></span></p>
<h2>The upload script</h2>
<p>First we&#8217;ll create a file that holds the FTP commands and then we&#8217;ll write a small batch script that uses the <code>ftp</code> command to execute the commands from the text file; have you ever read a sentence that uses the word <em>command</em> more often <img src='http://www.christianschenk.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ?</p>
<p>This is what the text file (<code>upload.ftp</code>) may look like:</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">open example.com
username
password
cd another-directory
mput C:filesfile*.txt
bye</pre></div></div>

<p>It will open a connection to the given host using the supplied username and password. Then it will change the working directory on the server to <code>another-directory</code> and finally upload some files. Adapt everything to your needs; if you&#8217;d like to use more FTP commands, <a title="List of FTP commands" href="http://en.wikipedia.org/wiki/List_of_FTP_commands">this</a> is a good starting point.</p>
<p>Next we&#8217;ll create a batch script that calls the <code>ftp</code> command using the text file that we&#8217;ve just created. Save the following into a batch file (<code>upload.bat</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">@echo off
@set logfile=upload.log
@ftp -i -v -s:&quot;upload.ftp&quot; &gt; %logfile%
@del %logfile%</pre></div></div>

<p>It creates a log file (<code>upload.log</code>) and deletes it after the <code>ftp</code> command is finished &#8211; if you&#8217;d like to keep the log file remove the last line from the script.</p>
<p>Now you have a batch file that you can click on and the files will be uploaded to the FTP server. Although this was pretty easy to setup is has a great impact: You don&#8217;t have to do this manually any more.</p>
<h3>Adding Automation</h3>
<p>While the script that you&#8217;ve just created is fully functional you may want to run it automatically every now and then. To do this, you&#8217;ll have to:</p>
<ul>
<li>make sure that the script uses absolute path names</li>
<li>add a task to the <code>at</code> scheduler</li>
</ul>
<p>First put the batch script and the text file into a directory of your choice. Add the path to this directory in front of log file&#8217;s name in line two of the batch script and to the text file containing the FTP commands in line three.</p>
<p>At last you can add a recurring task with <code>at</code> like so:</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">at 22:30 /every:M,T,W,Th,F,S,Su C:Scriptsupload.bat</pre></div></div>

<p>In this case the script that I put under <code>C:Scripts</code> will run every day at 22:30, i.e. 10:30 pm.</p>
<h2>Conclusion</h2>
<p>As we&#8217;ve seen it&#8217;s pretty easy to automatically upload files to some FTP server with Windows. For example, this comes in handy if you&#8217;d like to backup some files to another server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christianschenk.org/blog/automate-ftp-sessions-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
