Skip to content
Snippets Groups Projects
Commit 336d9c58 authored by joalhelk's avatar joalhelk
Browse files

retr update

parent 2afa363a
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -13,14 +13,13 @@ namespace FTPClient
static void Main(string[] args)
{
FtpClient client = new FtpClient(username, password, slackHost, port);
FtpClient client = new FtpClient(username, password, host, port);
client.Initialize();
client.LogIn();
client.List();
//client.Epsv();
client.Pasv();
client.List();
client.Retr();
client.List();
client.Quit();
Console.ReadKey();
}
......
......@@ -150,6 +150,11 @@ namespace FTPClient
}
}
/// <summary>
/// Handles PASV response
/// TODO: Parse IP from response
/// </summary>
/// <param name="response">Response from server</param>
private void handlePasvResponse(string response)
{
status = response.Substring(0,3);
......@@ -157,15 +162,14 @@ namespace FTPClient
int end = response.IndexOf(')');
string portsString = response.Substring(start+1, end-start-1);
string[] ports = portsString.Split(',');
int port = int.Parse(ports[ports.Length - 2]) * 256 + int.Parse(ports[ports.Length - 1]);
if (status == "227")
{
int portInt = int.Parse(ports[ports.Length-1]);
this.ftpPort = portInt;
this.ftpPort = port;
CreateSocket();
}
handleResponse(sr.ReadLine());
}
/// <summary>
......@@ -258,15 +262,17 @@ namespace FTPClient
/// </summary>
public void Retr()
{
string message = @"RETR pub";
string message = @"RETR README";
sw.WriteLine(message);
sw.Flush();
handleResponse(sr.ReadLine());
byte[] buffer = new byte[1024];
string file = string.Empty;
// TODO: Change default to break
// and cases just for statuses that need actions.
using (var sw = new StreamWriter(@"C:\Kurssit\ties323"))
switch(status)
{
case "553":
......@@ -276,10 +282,10 @@ namespace FTPClient
{
ftpSocket.Receive(buffer);
string response = Encoding.UTF8.GetString(buffer);
string test = ftpSr.ReadLine();
file += ftpSr.ReadLine();
if (response != null)
{
//Console.WriteLine(response);
sw.WriteLine(response);
}
else { break; }
}
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
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