by Adward [bigbom at tom dot com] posted on 2004/06/22 |
|
I used the proxysocket class to visit Ftp site. I can connect the site, but can't download and upload file. In my code:
public void download(string remoteFileName,string localFileName,ref string resultInfo)
{
...
TcpListener conn = new TcpListener(IPAddress.Any,Port());
conn.Start();
...
SendLine(m_pClient,"PASV mode");
reply = ReadLine(m_pClient);
...
SendLine(m_pClient,"RETR " + remoteFileName);
reply = ReadLine(m_pClient);
...
long startTime = DateTime.Now.Ticks;
while(!conn.Pending())
{
System.Threading.Thread.Sleep(50);
if((DateTime.Now.Ticks - startTime) / 10000 > 20000)
{
resultInfo = "Ftp server no response";
return;
}
}
using(Socket connectedFtpServer = conn.AcceptSocket())
{
conn.Stop();
int count = 1;
while(count > 0)
{
byte[] data = new Byte[1024];
count = connectedFtpServer.Receive(data,data.Length,SocketFlags.None);
output.Write(data,0,count);
output.Flush();
}
...
}
}
Help me thanks. |