S
sidd
Hi,
I am trying to ftp a file using socket class in system.net .
problem is it does not write the file on the server.
there are no errors.
below is the code
=============================
string strIPAddress;
int strPortNumber;
strIPAddress="IP address here";
strPortNumber=111;
IPEndPoint lep = new IPEndPoint(IPAddress.Parse(strIPAddress), strPortNumber);
Socket s = new Socket(lep.Address.AddressFamily,SocketType.Stream,ProtocolType.Tcp);
s.Connect(lep);
if (s.Connected)
{
string command = "USER Anonymous" ;
s.Send(Encoding.ASCII.GetBytes(command), mmand.Length, 0);
command = "PASS " ;
s.Send(Encoding.ASCII.GetBytes(command), command.Length, 0);
//reply is my sructure holds the code and message returned
commandReply reply = readCommandReply(s);
Debug.Write(reply.code.ToString() + " " + reply.message.ToString());
//NeedToRevisit : need to break it in small byte size before sending.
Byte[] SendFileBytes = Encoding.ASCII.GetBytes("File path to be uploaded");
SendFileHelper(SendFileBytes);
byte[] msg = aSendFileBytes;
// Blocks until send returns.
int i = s.Send(msg, 0, msg.Length, SocketFlags.None);
reply = readCommandReply(s);
Debug.Write(reply.code.ToString() + " " + reply.message.ToString());
// Blocks until read returns.
byte[] bytes = new byte[1024];
s.Receive(bytes, 0, s.Available, SocketFlags.None);
reply = readCommandReply(s);
Debug.Write(reply.code.ToString() + " " + reply.message.ToString());
//Displays to the screen.
//Console.WriteLine(Encoding.ASCII.GetString(bytes));
s.Shutdown(SocketShutdown.Both);
s.Close();
===========================
there is no error but it does not write the file.
also is this the right direction if you want to implement ftp in .net.
can i FTP a file using webrequest or one of it's decendent class.
thanks
sidd
I am trying to ftp a file using socket class in system.net .
problem is it does not write the file on the server.
there are no errors.
below is the code
=============================
string strIPAddress;
int strPortNumber;
strIPAddress="IP address here";
strPortNumber=111;
IPEndPoint lep = new IPEndPoint(IPAddress.Parse(strIPAddress), strPortNumber);
Socket s = new Socket(lep.Address.AddressFamily,SocketType.Stream,ProtocolType.Tcp);
s.Connect(lep);
if (s.Connected)
{
string command = "USER Anonymous" ;
s.Send(Encoding.ASCII.GetBytes(command), mmand.Length, 0);
command = "PASS " ;
s.Send(Encoding.ASCII.GetBytes(command), command.Length, 0);
//reply is my sructure holds the code and message returned
commandReply reply = readCommandReply(s);
Debug.Write(reply.code.ToString() + " " + reply.message.ToString());
//NeedToRevisit : need to break it in small byte size before sending.
Byte[] SendFileBytes = Encoding.ASCII.GetBytes("File path to be uploaded");
SendFileHelper(SendFileBytes);
byte[] msg = aSendFileBytes;
// Blocks until send returns.
int i = s.Send(msg, 0, msg.Length, SocketFlags.None);
reply = readCommandReply(s);
Debug.Write(reply.code.ToString() + " " + reply.message.ToString());
// Blocks until read returns.
byte[] bytes = new byte[1024];
s.Receive(bytes, 0, s.Available, SocketFlags.None);
reply = readCommandReply(s);
Debug.Write(reply.code.ToString() + " " + reply.message.ToString());
//Displays to the screen.
//Console.WriteLine(Encoding.ASCII.GetString(bytes));
s.Shutdown(SocketShutdown.Both);
s.Close();
===========================
there is no error but it does not write the file.
also is this the right direction if you want to implement ftp in .net.
can i FTP a file using webrequest or one of it's decendent class.
thanks
sidd