how to pass User and Pwrd with Sockets?

R

Ron

Greetings,

below is a sample app for connecting to a mainframe server
using Sockets for the purpose of using FTP service to
interact with it from a PC. I got as far as creating the
connection. But how do I pass a username and password?
How can I change directories?

---------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
using System.IO;

namespace TcpSocketClient
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnConnectToServer;
private System.Windows.Forms.Button btnSendMessage;
private StreamReader clientStreamReader;
private StreamWriter clientStreamWriter;

private System.ComponentModel.Container components =
null;
public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private bool ConnectToServer()
{
//connect to server at given port
try
{
TcpClient tcpClient = new TcpClient("173.31.15.37",
21);
Console.WriteLine("Connected to Server");
//get a network stream from server
NetworkStream clientSockStream = tcpClient.GetStream();
clientStreamReader = new StreamReader(clientSockStream);
clientStreamWriter = new StreamWriter(clientSockStream);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
return false;
}
return true;
}

private void btnConnectToServer_Click(object sender,
System.EventArgs e)
{
//connect to server
if (!ConnectToServer())
Console.WriteLine("Unable to connect to server");
}

private void btnSendMessage_Click(object sender,
System.EventArgs e)
{
try
{
//send message to server
clientStreamWriter.WriteLine("Hello!");
clientStreamWriter.Flush();
Console.WriteLine("SERVER: "+clientStreamReader.ReadLine
());
}
catch(Exception se)
{
Console.WriteLine(se.StackTrace);
}
}
}
}

Any resources on using Sockets and FTP appreciated.

Thanks,
Ron
 
A

Andrew

For these there are specific FTP commands to do each of those.
I'm pretty sure the CD dirname command is used to change directories and I
can't think of the the login commands at the moment. But try using the
following syntax in the connection string (e-mail address removed):password. I don't
know if it will work like that but it has been known to work in browsers.
 
C

Charles Calvert

below is a sample app for connecting to a mainframe server
using Sockets for the purpose of using FTP service to
interact with it from a PC. I got as far as creating the
connection. But how do I pass a username and password?
How can I change directories?

You need to learn the protocol. Think of it as a new API. The docs
are here: <http://www.faqs.org/rfcs/rfc959.html>. In a nutshell, you
send text to execute commands and receive text indicating the results.
You have to do your own text parsing. It might be easier to find a
class that someone has written and use that instead.
 
R

Ron

Thanks all for your replies. I have taken a look at the
FTP docs. Very informative. I have a little more
understanding what I am looking for now. Hopefully,
someone has put out a sample of code for doing this.


Thanks again,
Ron

-----Original Message-----
Greetings,

below is a sample app for connecting to a mainframe server
using Sockets for the purpose of using FTP service to
interact with it from a PC. I got as far as creating the
connection. But how do I pass a username and password?
How can I change directories?

---------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
using System.IO;

namespace TcpSocketClient
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnConnectToServer;
private System.Windows.Forms.Button btnSendMessage;
private StreamReader clientStreamReader;
private StreamWriter clientStreamWriter;

private System.ComponentModel.Container components =
null;
public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private bool ConnectToServer()
{
//connect to server at given port
try
{
TcpClient tcpClient = new TcpClient("173.31.15.37",
21);
Console.WriteLine("Connected to Server");
//get a network stream from server
NetworkStream clientSockStream = tcpClient.GetStream ();
clientStreamReader = new StreamReader (clientSockStream);
clientStreamWriter = new StreamWriter (clientSockStream);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
return false;
}
return true;
}

private void btnConnectToServer_Click(object sender,
System.EventArgs e)
{
//connect to server
if (!ConnectToServer())
Console.WriteLine("Unable to connect to server");
}

private void btnSendMessage_Click(object sender,
System.EventArgs e)
{
try
{
//send message to server
clientStreamWriter.WriteLine("Hello!");
clientStreamWriter.Flush();
Console.WriteLine
("SERVER: "+clientStreamReader.ReadLine
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Ron,

Look around for a FTP client component, it should be far easier that
implement one yourself

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Ron said:
Thanks all for your replies. I have taken a look at the
FTP docs. Very informative. I have a little more
understanding what I am looking for now. Hopefully,
someone has put out a sample of code for doing this.


Thanks again,
Ron

-----Original Message-----
Greetings,

below is a sample app for connecting to a mainframe server
using Sockets for the purpose of using FTP service to
interact with it from a PC. I got as far as creating the
connection. But how do I pass a username and password?
How can I change directories?

---------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
using System.IO;

namespace TcpSocketClient
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnConnectToServer;
private System.Windows.Forms.Button btnSendMessage;
private StreamReader clientStreamReader;
private StreamWriter clientStreamWriter;

private System.ComponentModel.Container components =
null;
public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private bool ConnectToServer()
{
//connect to server at given port
try
{
TcpClient tcpClient = new TcpClient("173.31.15.37",
21);
Console.WriteLine("Connected to Server");
//get a network stream from server
NetworkStream clientSockStream = tcpClient.GetStream ();
clientStreamReader = new StreamReader (clientSockStream);
clientStreamWriter = new StreamWriter (clientSockStream);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
return false;
}
return true;
}

private void btnConnectToServer_Click(object sender,
System.EventArgs e)
{
//connect to server
if (!ConnectToServer())
Console.WriteLine("Unable to connect to server");
}

private void btnSendMessage_Click(object sender,
System.EventArgs e)
{
try
{
//send message to server
clientStreamWriter.WriteLine("Hello!");
clientStreamWriter.Flush();
Console.WriteLine
("SERVER: "+clientStreamReader.ReadLine
());
}
catch(Exception se)
{
Console.WriteLine(se.StackTrace);
}
}
}
}

Any resources on using Sockets and FTP appreciated.

Thanks,
Ron
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top