FTPWebRequest无法获取GetRequestStream

时间:2016-09-03 20:40:44

标签: c#

感谢您查看我的问题。 我正在使用FTPWebRequest上传文件,但它无法正常工作。 这是我的代码。

ftp.KeepAlive = false;
ftp.UsePassive = true;

ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.UseBinary = true;
ftp.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Stream strm = ftp.GetRequestStream(); <--- Can't get request stream.
contentLen = fs.Read(buff, 0, buffLength);
error = null;

这是网络跟踪

System.Net Information: 0 : [7928] Associating FtpWebRequest#58093648 with FtpControlStream#60452428
System.Net.Sockets Verbose: 0 : [7928] Socket#30630844::Receive()
System.Net.Sockets Verbose: 0 : [7928] Data from Socket#30630844::Receive
System.Net.Sockets Verbose: 0 : [7928] 00000000 : 32 32 30 20 46 54 50 56-69 74 61 20 53 65 72 76 : 220 FTPVita Serv
System.Net.Sockets Verbose: 0 : [7928] 00000010 : 65 72 20 72 65 61 64 79-2E 0A                   : er ready..
System.Net.Sockets Verbose: 0 : [7928] Exiting Socket#30630844::Receive()   -> Int32#26
System.Net.Sockets Verbose: 0 : [7928] Socket#30630844::Receive()

然后抛出超时错误。

FTP服务器发送了220条欢迎消息,但无法获取Stream。

我尝试将UseBinary设置为FALSE,但仍无法正常工作..

任何想法???

感谢

0 个答案:

没有答案