问题描述
publicvoidUpload(stringfilename){stringftpServerIP="211.89.115.54:9007";FileInfofileInf=newFileInfo(filename);stringuri="ftp://"+ftpServerIP+"/"+fileInf.Name;FtpWebRequestreqFTP;//根据uri创建FtpWebRequest对象//reqFTP=(FtpWebRequest)FtpWebRequest.Create(newUri("ftp://"+ftpServerIP+"/"+fileInf.Name));reqFTP=(FtpWebRequest)FtpWebRequest.Create(newUri("ftp://"+ftpServerIP+"/"+fileInf.Name));//ftp用户名和密码stringftpUserID="llt0";stringftpPassword="$32w";reqFTP.Credentials=newNetworkCredential(ftpUserID,ftpPassword);//默认为true,连接不会被关闭//在一个命令之后被执行reqFTP.KeepAlive=false;//指定执行什么命令reqFTP.Method=WebRequestMethods.Ftp.UploadFile;//指定数据传输类型reqFTP.UseBinary=true;//上传文件时通知服务器文件的大小reqFTP.ContentLength=fileInf.Length;//缓冲大小设置为2kbintbuffLength=2048;byte[]buff=newbyte[buffLength];intcontentLen;//打开一个文件流(System.IO.FileStream)去读上传的文件FileStreamfs=fileInf.OpenRead();//把上传的文件写入流Streamstrm=reqFTP.GetRequestStream();//每次读文件流的2kbcontentLen=fs.Read(buff,0,buffLength);//流内容没有结束while(contentLen!=0){//把内容从filestream写入uploadstreamstrm.Write(buff,0,contentLen);contentLen=fs.Read(buff,0,buffLength);}//关闭两个流strm.Close();fs.Close();}程序执行到Streamstrm=reqFTP.GetRequestStream();时报异常System.Net.WebException:应PASV命令的请求,服务器返回了一个与FTP连接地址不同的地址。请各位大侠指点
解决方案
解决方案二:
参考下这篇文章http://www.codeproject.com/KB/IP/FtpClient.aspx
解决方案三:
upjf
解决方案四:
服务器和浏览器之间有防火墙吗
解决方案五:
有的话代码需要该吗?
解决方案六:
这个是网络的问题,不是代码本身的问题可以考虑对防火墙进行配置,让FTP程序直接访问服务器