Skip to content
Snippets Groups Projects
Commit 505c4404 authored by joalhelk's avatar joalhelk
Browse files

working connection ftp

parent 46b3a193
No related branches found
No related tags found
1 merge request!3Ftp client
Showing
with 225 additions and 0 deletions
File added

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FTPClient", "FTPClient\FTPClient.csproj", "{EB790FFB-D1D8-4C55-8AEA-84FADD41FE0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EB790FFB-D1D8-4C55-8AEA-84FADD41FE0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB790FFB-D1D8-4C55-8AEA-84FADD41FE0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB790FFB-D1D8-4C55-8AEA-84FADD41FE0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB790FFB-D1D8-4C55-8AEA-84FADD41FE0F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0CD7BE85-8058-4FD1-8D58-70CA5F7A636B}
EndGlobalSection
EndGlobal
using System;
namespace FTPClient
{
class Client
{
public static string username = "anynomous";
public static string password = "anynomous";
public static string host = "ftp.funet.fi";
public static int port = 21;
static void Main(string[] args)
{
FtpClient client = new FtpClient(username, password, host, port);
client.Initialize();
client.LogIn();
Console.ReadKey();
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace FTPClient
{
public class FtpClient
{
public static Socket socket;
public static IPEndPoint ipEndp;
public static NetworkStream ns;
public static StreamReader sr;
public static StreamWriter sw;
public string username { get; set; }
public string password { get; set; }
public string host { get; set; }
public int port { get; set; }
// Constructor
public FtpClient(string username, string password, string host, int port)
{
this.username = username;
this.password = password;
this.host = host;
this.port = port;
}
// Initialize socket and connect to server
public void Initialize()
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress[] ips = Dns.GetHostAddresses(host);
IPAddress address = ips[1];
ipEndp = new IPEndPoint(address, port);
try
{
socket.Connect(ipEndp);
} catch (Exception e)
{
Console.Write(e);
Console.ReadKey();
}
ns = new NetworkStream(socket);
sr = new StreamReader(ns);
sw = new StreamWriter(ns);
string response = sr.ReadLine();
Console.WriteLine(response);
}
public void LogIn()
{
sw.WriteLine("USER " + username);
sw.Flush();
string response = sr.ReadLine();
Console.WriteLine(response);
sw.WriteLine("PASS " + password);
sw.Flush();
response = sr.ReadLine();
Console.WriteLine(response);
}
public void GetDirectory()
{
try
{
socket.Connect(ipEndp);
} catch (Exception e)
{
Console.Write(e);
Console.ReadKey();
}
NetworkStream ns = new NetworkStream(socket);
StreamReader sr = new StreamReader(ns);
StreamWriter sw = new StreamWriter(ns);
string viesti = sr.ReadLine();
Console.WriteLine(viesti);
}
}
}
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.1",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v3.1": {
"FTPClient/1.0.0": {
"runtime": {
"FTPClient.dll": {}
}
}
}
},
"libraries": {
"FTPClient/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
\ No newline at end of file
File added
File added
File added
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Joppe\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Joppe\\.nuget\\packages"
]
}
}
\ No newline at end of file
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
\ No newline at end of file
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v3.1", FrameworkDisplayName = "")]
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("FTPClient")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("FTPClient")]
[assembly: System.Reflection.AssemblyTitleAttribute("FTPClient")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.
c740c62c19d0456ba793c0120c26262afecce061
File added
a4e69bfc552dac666e14bfb187fa62f229299f16
E:\Kurssit\ties323\FTPClient\FTPClient\bin\Debug\netcoreapp3.1\FTPClient.exe
E:\Kurssit\ties323\FTPClient\FTPClient\bin\Debug\netcoreapp3.1\FTPClient.deps.json
E:\Kurssit\ties323\FTPClient\FTPClient\bin\Debug\netcoreapp3.1\FTPClient.runtimeconfig.json
E:\Kurssit\ties323\FTPClient\FTPClient\bin\Debug\netcoreapp3.1\FTPClient.runtimeconfig.dev.json
E:\Kurssit\ties323\FTPClient\FTPClient\bin\Debug\netcoreapp3.1\FTPClient.dll
E:\Kurssit\ties323\FTPClient\FTPClient\bin\Debug\netcoreapp3.1\FTPClient.pdb
E:\Kurssit\ties323\FTPClient\FTPClient\obj\Debug\netcoreapp3.1\FTPClient.csprojAssemblyReference.cache
E:\Kurssit\ties323\FTPClient\FTPClient\obj\Debug\netcoreapp3.1\FTPClient.AssemblyInfoInputs.cache
E:\Kurssit\ties323\FTPClient\FTPClient\obj\Debug\netcoreapp3.1\FTPClient.AssemblyInfo.cs
E:\Kurssit\ties323\FTPClient\FTPClient\obj\Debug\netcoreapp3.1\FTPClient.csproj.CoreCompileInputs.cache
E:\Kurssit\ties323\FTPClient\FTPClient\obj\Debug\netcoreapp3.1\FTPClient.dll
E:\Kurssit\ties323\FTPClient\FTPClient\obj\Debug\netcoreapp3.1\FTPClient.pdb
E:\Kurssit\ties323\FTPClient\FTPClient\obj\Debug\netcoreapp3.1\FTPClient.genruntimeconfig.cache
File added
File added
e7930741b859f33aced304b7bf7f3548c9c8a4f8
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment