Skip to content

Commit cae2ba4

Browse files
Initial version
1 parent 3d6d4a7 commit cae2ba4

13 files changed

+362
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bin
2+
obj/Release
3+
obj
4+
.vs

FetchFolderCommand.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using CommandLine;
3+
using FluentFTP;
4+
5+
namespace Ftp.Client
6+
{
7+
[Verb("fetch-folder", HelpText = "Fetch folder content list")]
8+
public class FetchFolderCommand : FtpCommand
9+
{
10+
[Option('p', "path", Required = true)]
11+
public string Path
12+
{
13+
get;
14+
set;
15+
}
16+
17+
public override void Execute()
18+
{
19+
var ftpClient = new FtpClient(Host, UserName, Password);
20+
21+
try
22+
{
23+
if (EnableSsl)
24+
{
25+
ftpClient.EncryptionMode = FtpEncryptionMode.Explicit;
26+
ftpClient.DataConnectionType = FtpDataConnectionType.PORT;
27+
}
28+
29+
if (!string.IsNullOrEmpty(ExternalIp))
30+
ftpClient.AddressResolver = () => ExternalIp;
31+
32+
if (EnablePassive)
33+
ftpClient.DataConnectionType = FtpDataConnectionType.AutoPassive;
34+
35+
ftpClient.Connect();
36+
37+
var listing = ftpClient.GetNameListing(Path);
38+
39+
Console.WriteLine("Result: ");
40+
foreach (var s in listing)
41+
{
42+
Console.WriteLine(s);
43+
}
44+
45+
Console.WriteLine("Press any key to exit...");
46+
Console.ReadLine();
47+
}
48+
catch (Exception ex)
49+
{
50+
Console.WriteLine(ex);
51+
}
52+
finally
53+
{
54+
ftpClient.Disconnect();
55+
}
56+
57+
}
58+
}
59+
}

FileUploadCommand.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using CommandLine;
3+
using FluentFTP;
4+
5+
namespace Ftp.Client
6+
{
7+
[Verb("upload-file", HelpText = "Upload file from local path to a remote path")]
8+
public class FileUploadCommand : FtpCommand
9+
{
10+
[Option('p', "path", Required = true)]
11+
public string Path
12+
{
13+
get;
14+
set;
15+
}
16+
17+
[Option('f', "local-path", Required = true, HelpText = "Local path of the file to upload")]
18+
public string LocalFile
19+
{
20+
get;
21+
set;
22+
}
23+
24+
public override void Execute()
25+
{
26+
var ftpClient = new FtpClient(Host, UserName, Password);
27+
28+
try
29+
{
30+
if (EnableSsl)
31+
{
32+
ftpClient.EncryptionMode = FtpEncryptionMode.Explicit;
33+
ftpClient.DataConnectionType = FtpDataConnectionType.PORT;
34+
}
35+
36+
if (!string.IsNullOrEmpty(ExternalIp))
37+
ftpClient.AddressResolver = () => ExternalIp;
38+
39+
if (EnablePassive)
40+
ftpClient.DataConnectionType = FtpDataConnectionType.AutoPassive;
41+
42+
ftpClient.Connect();
43+
44+
var result = ftpClient.UploadFile(LocalFile, Path);
45+
46+
47+
Console.WriteLine("Result: ");
48+
Console.WriteLine(result);
49+
50+
Console.WriteLine("Press any key to exit...");
51+
Console.ReadLine();
52+
}
53+
catch (Exception ex)
54+
{
55+
Console.WriteLine(ex);
56+
}
57+
finally
58+
{
59+
ftpClient.Disconnect();
60+
}
61+
62+
}
63+
}
64+
}

Ftp.Client.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="CommandLineParser" Version="2.8.0" />
10+
<PackageReference Include="FluentFTP" Version="35.2.2" />
11+
</ItemGroup>
12+
13+
</Project>

Ftp.Client.csproj.user

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<_LastSelectedProfileId>C:\Users\f.bekran\src\FtpChecker\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
5+
</PropertyGroup>
6+
</Project>

Ftp.Client.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ftp.Client", "Ftp.Client.csproj", "{4B8B2596-EA85-4F67-8325-BB455CF9C334}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{4B8B2596-EA85-4F67-8325-BB455CF9C334}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{4B8B2596-EA85-4F67-8325-BB455CF9C334}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{4B8B2596-EA85-4F67-8325-BB455CF9C334}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{4B8B2596-EA85-4F67-8325-BB455CF9C334}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5B8678E1-1F5B-46F3-B5B5-E2739A4A2153}
24+
EndGlobalSection
25+
EndGlobal

FtpCommand.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using CommandLine;
5+
6+
namespace Ftp.Client
7+
{
8+
public class FtpCommand : ICommand
9+
{
10+
[Option('h', "Host", Required = true)]
11+
public string Host
12+
{
13+
get;
14+
set;
15+
}
16+
17+
[Option('u', "username", Required = true)]
18+
public string UserName
19+
{
20+
get;
21+
set;
22+
}
23+
24+
[Option('s', "password", Required = false)]
25+
public string Password
26+
{
27+
get;
28+
set;
29+
}
30+
31+
[Option('l', "ssl", Required = false, HelpText = "Enable ssl support")]
32+
public bool EnableSsl
33+
{
34+
get;
35+
set;
36+
}
37+
38+
[Option('v', "passive", Required = false, HelpText = "Set true to enable passive mode")]
39+
public bool EnablePassive
40+
{
41+
get;
42+
set;
43+
}
44+
45+
[Option('e', "external-ip", Required = false, HelpText = "Set this parameter to your NAT outgoing IP if you are operating within a NAT")]
46+
public string ExternalIp
47+
{
48+
get;
49+
set;
50+
}
51+
52+
53+
54+
public virtual void Execute()
55+
{
56+
57+
}
58+
}
59+
}

ICommand.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Ftp.Client
4+
{
5+
public interface ICommand
6+
{
7+
void Execute();
8+
}
9+
}

Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using CommandLine;
3+
4+
namespace Ftp.Client
5+
{
6+
internal class Program
7+
{
8+
9+
static void Main(string[] args)
10+
{
11+
if (args.Length == 0)
12+
{
13+
Console.WriteLine("Invalid args");
14+
return;
15+
}
16+
17+
Parser.Default.ParseArguments<FetchFolderCommand, FileUploadCommand>(args).WithParsed(t => ((ICommand)t).Execute());
18+
19+
Console.WriteLine("Press any key to close...");
20+
}
21+
}
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<Configuration>Release</Configuration>
8+
<Platform>Any CPU</Platform>
9+
<PublishDir>bin\Release\netcoreapp3.1\publish\win-x86\</PublishDir>
10+
<PublishProtocol>FileSystem</PublishProtocol>
11+
<TargetFramework>net6.0</TargetFramework>
12+
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
13+
<SelfContained>true</SelfContained>
14+
<PublishSingleFile>True</PublishSingleFile>
15+
<PublishReadyToRun>False</PublishReadyToRun>
16+
</PropertyGroup>
17+
</Project>

0 commit comments

Comments
 (0)