C# 到ftp的套接字连接未接收应答
我正在使用C#,VisualStudio2008,用于嵌入式设备的Framework2.0 我在使用套接字连接与FTP通信时遇到问题 为了你们能帮助我,我写了一段话来解释我的烦恼C# 到ftp的套接字连接未接收应答,c#,sockets,ftp,C#,Sockets,Ftp,我正在使用C#,VisualStudio2008,用于嵌入式设备的Framework2.0 我在使用套接字连接与FTP通信时遇到问题 为了你们能帮助我,我写了一段话来解释我的烦恼 IPEndPoint endpoint; Socket cmdsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress address
IPEndPoint endpoint;
Socket cmdsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress address = IPAddress.Parse(args[0]);
endpoint = new IPEndPoint(address, int.Parse(args[1]));
// Connection
cmdsocket.Connect(endpoint);
if (cmdsocket.Connected)
{
do
{
Console.WriteLine("Type the command to send : ");
string l_sCommandToSend = Console.ReadLine();
Console.WriteLine("Do you want a timeout to receive ? (Y/N (default))");
string l_sReceiveTimeout = Console.ReadLine();
// Sending
byte[] bytes = Encoding.ASCII.GetBytes((l_sCommandToSend + "\r\n").ToCharArray());
cmdsocket.Send(bytes, bytes.Length, 0);
if (l_sReceiveTimeout == "Y")
{
Thread.Sleep(1000);
}
// Receiving
byte[] bufferToRead = new byte[512];
string l_sResponsetext = "";
int l_iByteReceivedCount = 0;
while (cmdsocket.Available > 0)
{
Console.WriteLine("Receiving...");
l_iByteReceivedCount = cmdsocket.Receive(bufferToRead, SocketFlags.None);
l_sResponsetext += Encoding.ASCII.GetString(bufferToRead, 0, l_iByteReceivedCount);
Console.WriteLine("Bytes Received : " + l_iByteReceivedCount);
Console.WriteLine("l_sResponsetext : " + l_sResponsetext);
}
Console.WriteLine("This is the answer : " + l_sResponsetext);
} while (true);
}
Console.WriteLine("Job done.");
Console.ReadLine();
// Fermeture du socket
cmdsocket.Close();
cmdsocket = null;
上面是一个片段:
- 连接到FTP(我在服务器端使用FileZilla服务器进行测试)
- 询问用户要发送的命令
- 询问用户是否希望在发送和接收之间睡眠(稍后详细信息)
- 阅读并显示答案
我在这里做错了什么?我正在编写一个ftp服务器,在连接开始时,我正在做的是:
streamWrite.WriteLine("220 'Any text here'");
streamWrite.Flush();
试着先阅读你的客户