问题描述
哪位大神有代码,使用C#完成上传文件到服务器的源码
解决方案
解决方案二:
googleWebClient.UploadFile
解决方案三:
解决方案四:
///<summary>///上传文件///</summary>///<paramname="filename"></param>privatestringUpload(stringfilename){FileInfofileInf=newFileInfo(filename);if(!fileInf.Exists){returnfilename+"不存在!n";}stringuri=ftpURI+fileInf.Name;FtpWebRequestreqFTP;reqFTP=(FtpWebRequest)FtpWebRequest.Create(newUri(uri));reqFTP.Credentials=newNetworkCredential(ftpUserID,ftpPassword);reqFTP.KeepAlive=false;reqFTP.Method=WebRequestMethods.Ftp.UploadFile;reqFTP.UseBinary=true;reqFTP.UsePassive=false;//选择主动还是被动模式//EnteringPassiveModereqFTP.ContentLength=fileInf.Length;intbuffLength=2048;byte[]buff=newbyte[buffLength];intcontentLen;FileStreamfs=fileInf.OpenRead();try{Streamstrm=reqFTP.GetRequestStream();contentLen=fs.Read(buff,0,buffLength);while(contentLen!=0){strm.Write(buff,0,contentLen);contentLen=fs.Read(buff,0,buffLength);}strm.Close();fs.Close();}catch(Exceptionex){return"同步"+filename+"时连接不上服务器!n";//Insert_Standard_ErrorLog.Insert("FtpWeb","UploadError-->"+ex.Message);}return"";}