问题描述
publicvoidConnect(){socketControl=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);IPEndPointep=newIPEndPoint(IPAddress.Parse(RemoteHost),strRemotePort);//链接try{socketControl.Connect(ep);}catch(Exception){thrownewIOException("Couldn'tconnecttoremoteserver");}//获取应答码ReadReply();if(iReplyCode!=220){DisConnect();thrownewIOException(strReply.Substring(4));}//登录SendCommand("USER"+strRemoteUser);if(!(iReplyCode==331||iReplyCode==230)){CloseSocketConnect();//关闭连接thrownewIOException(strReply.Substring(4));}if(iReplyCode!=230){SendCommand("PASS"+strRemotePass);if(!(iReplyCode==230||iReplyCode==202)){CloseSocketConnect();//关闭连接thrownewIOException(strReply.Substring(4));}}bConnected=true;//切换到目录ChDir(strRemotePath);}//删除PublicvoidDeleteFTP(stringfileName){try{stringuri="ftp://"+ftpServerIP+"/"+fileName;if(file!=null){uri="ftp://"+ftpServerIP+"/"+file+fileName;}//连接FTPConnect(uri);reqFTP.KeepAlive=false;reqFTP.Method=WebRequestMethods.Ftp.DeleteFile;if(lb_file.SelectedItem.ToString().Contains("文件夹")){reqFTP.Method=WebRequestMethods.Ftp.RemoveDirectory;}stringresult=String.Empty;FtpWebResponseresponse=(FtpWebResponse)reqFTP.GetResponse();longsize=response.ContentLength;Streamdatastream=response.GetResponseStream();StreamReadersr=newStreamReader(datastream);result=sr.ReadToEnd();sr.Close();datastream.Close();response.Close();detailListfile();}catch(Exceptione){MessageBox.Show(e.Message,"删除出错");}finally{}}publicvoidGet(stringstrRemoteFileName,stringstrFolder,stringstrLocalFileName){if(!bConnected){Connect();}SetTransferType(TransferType.Binary);if(strLocalFileName.Equals("")){strLocalFileName=strRemoteFileName;}if(!File.Exists(strLocalFileName)){Streamst=File.Create(strLocalFileName);st.Close();}FileStreamoutput=newFileStream(strFolder+"\"+strLocalFileName,FileMode.Create);SocketsocketData=CreateDataSocket();SendCommand("RETR"+strRemoteFileName);if(!(iReplyCode==150||iReplyCode==125||iReplyCode==226||iReplyCode==250)){thrownewIOException(strReply.Substring(4));}while(true){intiBytes=socketData.Receive(buffer,buffer.Length,0);output.Write(buffer,0,iBytes);if(iBytes<=0){break;}}output.Close();if(socketData.Connected){socketData.Close();}if(!(iReplyCode==226||iReplyCode==250)){ReadReply();if(!(iReplyCode==226||iReplyCode==250)){thrownewIOException(strReply.Substring(4));}
解决方案
解决方案二:
用socket操作ftp?不熟悉ftp协议@_@...纯支持.
解决方案三:
板凳
解决方案四:
很多看不懂啊,学习
解决方案五:
没用过求知
解决方案六:
C#操作Ftp实现下载,删除文件,获得文件列表等
解决方案七:
呵呵你这个太有意思了。连接自己编写。获取数据用微软的。
解决方案八:
帮你顶起来