public void login()
{ clientSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry(remoteHost).AddressList[0], remotePort); try
{
clientSocket.Connect(ep);
}
catch(Exception)
{
throw new IOException("Couldn't connect to remote server");
} readReply();
if(retValue != 220)
{
close();
throw new IOException(reply.Substring(4));
}
if(debug)
//Console.WriteLine("USER "+remoteUser); sendCommand("USER "+remoteUser); if( !(retValue == 331 || retValue == 230) )
{
cleanup();
//throw new IOException(reply.Substring(4));
} if( retValue != 230 )
{
if(debug)
//Console.WriteLine("PASS xxx"); sendCommand("PASS "+remotePass);
if( !(retValue == 230 || retValue == 202) )
{
cleanup();
//throw new IOException(reply.Substring(4));
}
} logined = true;
//Console.WriteLine("Connected to "+remoteHost); chdir(remotePath); } ///
/// Close the FTP connection.
///
public void close()
{ if (clientSocket != null)
{
sendCommand("QUIT");
} cleanup();
//Console.WriteLine("Closing...");
}
#endregion #region 设置FTP文件读取模式
/// <summary>
/// 设置FTP文件读取模式(二进制、文本)
/// </summary>
/// <param name="mode">文件读取模式(二进制(True)、文本(False))</param>
public void setBinaryMode(Boolean mode)
{
if(mode)
{
sendCommand("TYPE I");
}
else
{
sendCommand("TYPE A");
}
if (retValue != 200)
{
throw new IOException(reply.Substring(4));
}
} private void sendCommand(String command)
{
Byte[] cmdBytes =
GetEncoding().GetBytes((command+"\r\n").ToCharArray());
clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
readReply(); }运行到clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
提示未将对象引用设置到对象的实例 怎么回事呢
{ clientSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry(remoteHost).AddressList[0], remotePort); try
{
clientSocket.Connect(ep);
}
catch(Exception)
{
throw new IOException("Couldn't connect to remote server");
} readReply();
if(retValue != 220)
{
close();
throw new IOException(reply.Substring(4));
}
if(debug)
//Console.WriteLine("USER "+remoteUser); sendCommand("USER "+remoteUser); if( !(retValue == 331 || retValue == 230) )
{
cleanup();
//throw new IOException(reply.Substring(4));
} if( retValue != 230 )
{
if(debug)
//Console.WriteLine("PASS xxx"); sendCommand("PASS "+remotePass);
if( !(retValue == 230 || retValue == 202) )
{
cleanup();
//throw new IOException(reply.Substring(4));
}
} logined = true;
//Console.WriteLine("Connected to "+remoteHost); chdir(remotePath); } ///
/// Close the FTP connection.
///
public void close()
{ if (clientSocket != null)
{
sendCommand("QUIT");
} cleanup();
//Console.WriteLine("Closing...");
}
#endregion #region 设置FTP文件读取模式
/// <summary>
/// 设置FTP文件读取模式(二进制、文本)
/// </summary>
/// <param name="mode">文件读取模式(二进制(True)、文本(False))</param>
public void setBinaryMode(Boolean mode)
{
if(mode)
{
sendCommand("TYPE I");
}
else
{
sendCommand("TYPE A");
}
if (retValue != 200)
{
throw new IOException(reply.Substring(4));
}
} private void sendCommand(String command)
{
Byte[] cmdBytes =
GetEncoding().GetBytes((command+"\r\n").ToCharArray());
clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
readReply(); }运行到clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
提示未将对象引用设置到对象的实例 怎么回事呢
if( !(retValue == 331 || retValue == 230) )
{
cleanup();
throw new IOException(reply.Substring(4));
}
在登陆时retValue等示220
throw new IOException(reply.Substring(4));
这个提示
Serv-U FTP Server v6.4 for WinSock ready...这又是怎么回来呢