Skip to content

Commit

Permalink
fixed bugs in ftp
Browse files Browse the repository at this point in the history
  • Loading branch information
vmelamed committed Sep 2, 2016
1 parent 096190f commit fe8f3d6
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Aspects/Test/TestFtpClient/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
51 changes: 51 additions & 0 deletions Aspects/Test/TestFtpClient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using vm.Aspects;
using vm.Aspects.FtpTransfer;

namespace TestFtpClient
{
class Program
{
static void Main(string[] args)
{
try
{
var site = new TransferSite
{
Link = "ftp://ftp.testalmond.net",
EnableSsl = true,
UseBinary = true,
TransmissionDirection = TransmissionDirection.Inbound,
ClientCertificate = new CertificateData
{
StoreLocation = StoreLocation.LocalMachine,
StoreName = StoreName.My,
FindBy = X509FindType.FindByThumbprint,
FindByValue = "8114d495c16247dac51c586af91eb0d42c2d1ccf",
},
Credentials = new FtpUserCredentials
{
UserName = "val",
Password = "Almond123"
},
};

using (var rdr = new StreamReader(site.ListFiles()))
Console.WriteLine(rdr.ReadToEnd());
}
catch (Exception x)
{
var dump = x.DumpString();

Console.WriteLine(dump);
Debug.WriteLine(dump);
}

Console.WriteLine("Press any key to finish...");
Console.ReadKey(true);
}
}
}
36 changes: 36 additions & 0 deletions Aspects/Test/TestFtpClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TestFtpClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestFtpClient")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("73b4c51d-31ee-4dbc-b7e9-fa13ff817f1d")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
70 changes: 70 additions & 0 deletions Aspects/Test/TestFtpClient/TestFtpClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestFtpClient</RootNamespace>
<AssemblyName>TestFtpClient</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Diagnostics\vm.Aspects.Diagnostics.ObjectDumper.csproj">
<Project>{372A2FEF-C004-498C-B57F-CF0ACA66C37B}</Project>
<Name>vm.Aspects.Diagnostics.ObjectDumper</Name>
</ProjectReference>
<ProjectReference Include="..\..\vm.Aspects.FtpTransfer\vm.Aspects.FtpTransfer.csproj">
<Project>{113ce397-4859-4b92-8f10-e5ba2d6f1a35}</Project>
<Name>vm.Aspects.FtpTransfer</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
18 changes: 11 additions & 7 deletions Aspects/vm.Aspects.FtpTransfer/TransferSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class TransferSite : ITransferFile
/// The default implementation here allows for self-signed certificate within the intranet and
/// the local computer otherwise it fails if the server certificate is not kosher.
/// </remarks>
protected bool ServerCertificateValidation(
bool ServerCertificateValidation(
object sender,
X509Certificate certificate,
X509Chain chain,
Expand Down Expand Up @@ -129,8 +129,9 @@ protected bool ServerCertificateValidation(
public Stream ListFiles()
{
var request = PrepareFileRequest(WebRequestMethods.Ftp.ListDirectoryDetails, null);
var response = request.GetResponse();

return request.GetRequestStream();
return response.GetResponseStream();
}

/// <summary>
Expand All @@ -141,8 +142,9 @@ public Stream ListFiles()
public Stream DownloadFile(string name)
{
var request = PrepareFileRequest(WebRequestMethods.Ftp.DownloadFile, name);
var response = request.GetResponse();

return request.GetRequestStream();
return response.GetResponseStream();
}

/// <summary>
Expand All @@ -154,21 +156,23 @@ public Stream DownloadFile(string name)
public void UploadFile(Stream stream, string name)
{
var request = PrepareFileRequest(WebRequestMethods.Ftp.UploadFile, name);

var targetStream = request.GetRequestStream();

stream.CopyTo(targetStream);
}

// ---------------------------------------------------------------------------

/// <summary>
/// Asynchronously lists the files available for receiving at the target (something like dir).
/// </summary>
/// <returns>The stream that will receive the files list text. The interpretation of the list text is up to the consumer.</returns>
public async Task<Stream> ListFilesAsync()
{
var request = PrepareFileRequest(WebRequestMethods.Ftp.ListDirectoryDetails, null);
var response = await request.GetResponseAsync();

return await request.GetRequestStreamAsync();
return response.GetResponseStream();
}

/// <summary>
Expand All @@ -179,8 +183,9 @@ public async Task<Stream> ListFilesAsync()
public async Task<Stream> DownloadFileAsync(string name)
{
var request = PrepareFileRequest(WebRequestMethods.Ftp.DownloadFile, name);
var response = await request.GetResponseAsync();

return await request.GetRequestStreamAsync();
return response.GetResponseStream();
}

/// <summary>
Expand All @@ -192,7 +197,6 @@ public async Task<Stream> DownloadFileAsync(string name)
public async Task UploadFileAsync(Stream stream, string name)
{
var request = PrepareFileRequest(WebRequestMethods.Ftp.UploadFile, name);

var targetStream = await request.GetRequestStreamAsync();

await stream.CopyToAsync(targetStream);
Expand Down
11 changes: 10 additions & 1 deletion vm.Aspects.sln
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vm.Aspects.Wcf.Tests", "Asp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vm.Aspects.FtpTransfer", "Aspects\vm.Aspects.FtpTransfer\vm.Aspects.FtpTransfer.csproj", "{113CE397-4859-4B92-8F10-E5BA2D6F1A35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestFtpClient", "Aspects\Test\TestFtpClient\TestFtpClient.csproj", "{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -195,6 +197,12 @@ Global
{113CE397-4859-4B92-8F10-E5BA2D6F1A35}.DebugUnitTest|Any CPU.Build.0 = Debug|Any CPU
{113CE397-4859-4B92-8F10-E5BA2D6F1A35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{113CE397-4859-4B92-8F10-E5BA2D6F1A35}.Release|Any CPU.Build.0 = Release|Any CPU
{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}.DebugUnitTest|Any CPU.ActiveCfg = Debug|Any CPU
{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}.DebugUnitTest|Any CPU.Build.0 = Debug|Any CPU
{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -212,9 +220,10 @@ Global
{5E36D04C-CDA1-4E17-B7AF-3A139B8FB87D} = {A9DCD77C-A0E2-4D01-AB1D-40F8853D4FB2}
{32B9F323-F629-4CA4-9003-0E30A4C441A0} = {A9DCD77C-A0E2-4D01-AB1D-40F8853D4FB2}
{9F87B835-8270-42F9-9567-26B2C7489C2B} = {B2E493FE-EFCF-4D0B-84C5-5C75B0D361B8}
{73B4C51D-31EE-4DBC-B7E9-FA13FF817F1D} = {B2E493FE-EFCF-4D0B-84C5-5C75B0D361B8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = packages\EnterpriseLibrary.Common.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.ExceptionHandling.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Logging.5.0.505.1\lib\NET35;packages\EnterpriseLibrary.ExceptionHandling.Logging.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.PolicyInjection.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Validation.5.0.505.0\lib\NET35
EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.Common.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.Logging.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.ExceptionHandling.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.Validation.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.ExceptionHandling.Logging.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.PolicyInjection.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.ExceptionHandling.WCF.6.0.1304.0\lib\NET45;packages\EnterpriseLibrary.Validation.Integration.WCF.6.0.1304.0\lib\NET45
EnterpriseLibraryConfigurationToolBinariesPath = packages\EnterpriseLibrary.Common.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.ExceptionHandling.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Logging.5.0.505.1\lib\NET35;packages\EnterpriseLibrary.ExceptionHandling.Logging.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.PolicyInjection.5.0.505.0\lib\NET35;packages\EnterpriseLibrary.Validation.5.0.505.0\lib\NET35
EndGlobalSection
EndGlobal

0 comments on commit fe8f3d6

Please sign in to comment.