Disclaimer
The following is already said in BSD-license (see license.txt in downloaded package), but again -
some operations can work not in the way you expected.
It's your responsibility to decide if you want to use it or not.
If you decided to use it and something went wrong -
it was your decision, so the only person to blame is you.
Another thing - the project is still in alpha/beta stage, so names of tasks, modules,
functions, properties, etc. are subjects to change.
Important usage note
In the current implementation all ftp operation are synchronous, and files are loaded in memory before upload.
In other words - don't use it for large files.
FtpTask
Usage
There are several different ways to archieve it. Here is the simplest one.
- Download the latest release.
- Extract ftptask.dll assembly to directory with your build script.
- Add a reference to the assembly from your script:
<UsingTask AssemblyFile="FtpTask.dll" TaskName="FtpTask"/>
- Add a ftp task you need. The following tasks are available:
Examples
The following are small MSBuild scripts or snippets to show on how to use the ftptask.
Cleanup ftp directory
Recursively deletes all files and sub-directories from the specified ftp directory.
Be sure you want it. :)
<Project DefaultTargets="Foo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="FtpTask.dll" TaskName="FtpTask"/>
<Target Name="Foo">
<FtpTask
Action="Cleanup"
Address="localhost"
RemoteDir="/Atlas"
/>
</Target>
</Project>
Upload a directory to ftp server
<Project DefaultTargets="Foo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="FtpTask.dll" TaskName="FtpTask" />
<Target Name="Foo">
<FtpTask
Action="Upload"
Address="localhost"
RemoteDir="/Atlas"
LocalDir="D:\Downloads\DevTools\Atlas"
/>
</Target>
</Project>
Cleanup and upload
This task was the purpose of the project. Deletes everything from ftp server, and uploads a fresh version of the website.
<Project DefaultTargets="Foo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="FtpTask.dll" TaskName="FtpTask"/>
<Target Name="Foo">
<FtpTask
Action="CleanupAndUpload"
Address="localhost"
RemoteDir="/WiX"
LocalDir="D:\Downloads\DevTools\CVS"
/>
</Target>
</Project>
Authentication
<Project DefaultTargets="Foo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="FtpTask.dll" TaskName="FtpTask"/>
<Target Name="Foo">
<FtpTask
Action="Cleanup"
Address="localhost"
RemoteDir="/Atlas"
UserName="Demo"
Password="Demo"
/>
</Target>
</Project>
FtpClient library
Overview
A wrapper for FtpWebRequest.
FtpParse library
Overview
The module contains a single static function which is do everything. The static function parses one line from ftp server response on LIST command.
If parsing succeeded it returns an instance of class with extracted information - name,
is it a file or a directory, file size, modification time.
The function returns null if the line cannot be parsed.
Example
StringReader reader = new StringReader(responseLIST);
while (true)
{
string line = reader.ReadLine();
if (null == line) break; // it was the last line
// parse the response line, and act depends on the item type
FtpParse info = FtpParse.Parse(line);
if (null != info)
{
switch (info.type)
{
case FtpParse.Type.File:
files.Add(info.name);
break;
case FtpParse.Type.Directory:
dirs.Add(info.name);
break;
}
}
}
|