FTPWebRequest:基础连接已关闭:接收时发生意外错误

时间:2015-09-21 05:33:00

标签: c# ftp

将文件上传到FTP服务器时遇到问题。此连接通常可以在本地连接上正常工作 - 但是,我尝试连接到系统的公共IP地址(ftp://xx.xxx.xxx.xx)。我可以通过filezilla连接到它上传和下载文件 - 但是,由于某种原因,这似乎不起作用。

这是用于创建WebRequest的代码:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://xx.xxx.xx.xxx" + uploadPath);
request.UseBinary = true; 
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.UploadFile;

在调试模式下运行正常,允许所有文件路径等。但是,代码在此部分引发错误:

byte[] b = File.ReadAllBytes(tarPath);
request.ContentLength = b.Length;
using (Stream s = request.GetRequestStream())
{
    s.Write(b, 0, b.Length);
}
FtpWebResponse ftpResp = (FtpWebResponse)request.GetResponse();
if (ftpResp != null)
{
    Debug.WriteLine(ftpResp.StatusDescription);
}

任何想法?我搜索了有关此错误的各种在线帖子,其中大多数都是关于HTTPWebRequest,而不是FTPWebRequest。因此,如果此代码在本地连接上运行,那么为什么它在全局连接中表现如此?

提前致谢

EDIT 根据要求,我已启用网络日志记录,这是输出 - 请记住,出于安全原因,我已将公共服务器IP更改为00x000x00x000,这不是错误! :)

System.Net Information: 0 : [7120] FtpWebRequest#35287174::.ctor(ftp://00.000.00.000/users/be83dec5d120c42a6b94/119ab9d171cce2528d9a.tar)
System.Net Information: 0 : [7120] FtpWebRequest#35287174::GetRequestStream(Method=STOR.)
System.Net Information: 0 : [7120] Current OS installation type is 'Client'.
System.Net Information: 0 : [7120] RAS supported: True
System.Net Error: 0 : [7120] Can't retrieve proxy settings for Uri 'ftp://00.000.00.000/users/be83dec5d120c42a6b94/119ab9d171cce2528d9a.tar'. Error code: 12180.
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Created connection from 192.168.0.48:15275 to 00.000.00.000:21.
System.Net Information: 0 : [7120] Associating FtpWebRequest#35287174 with FtpControlStream#10261382
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [220 (vsFTPd 3.0.2)]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [USER dev]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [331 Please specify the password.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [PASS ********]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [230 Login successful.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [200 Always in UTF8 mode.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [PWD]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [257 "/home/dev"]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [TYPE I]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [200 Switching to Binary mode.]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [PASV]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [227 Entering Passive Mode (58,104,53,147,24,79).]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Sending command [STOR users/be83dec5d120c42a6b94/119ab9d171cce2528d9a.tar]
System.Net Information: 0 : [7120] FtpControlStream#10261382 - Received response [150 Ok to send data.]
System.Net Information: 0 : [5756] ServicePoint#22597652 - Closed as idle.
System.Net Information: 0 : [7120] FtpWebRequest#35287174::(Releasing FTP connection#10261382.)
System.Net Error: 0 : [7120] Exception in AppDomain#4032828::UnhandledExceptionHandler - The underlying connection was closed: An unexpected error occurred on a receive..
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Stream.Dispose()
   at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
   at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.Abort(Exception e)
   at System.Net.CommandStream.CheckContinuePipeline()
   at System.Net.FtpWebRequest.DataStreamClosed(CloseExState closeState)
   at System.Net.FtpDataStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
   at System.Net.FtpDataStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Stream.Dispose()
   at tcpClient.ftpClass.upload(String tarPath, String uploadPath) in c:\Users\Adam\Desktop\Project\Workspace\Network\SafeSpotService\SafeSpotClient\SafeSpotClient\ftpClass.cs:line 84
   at SafeSpotClient.Service1.checkInCycle(String macAddr) in c:\Users\Adam\Desktop\Project\Workspace\Network\SafeSpotService\SafeSpotClient\SafeSpotClient\Service1.cs:line 121
   at SafeSpotClient.Service1.Callback(Object state) in c:\Users\Adam\Desktop\Project\Workspace\Network\SafeSpotService\SafeSpotClient\SafeSpotClient\Service1.cs:line 168
   at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()
   at System.Threading.TimerQueue.AppDomainTimerCallback()

0 个答案:

没有答案