2012-01-06 141 views
1

私は、ファイルをアップロードするためにバックグラウンドワーカーを使用しているWindowsフォームアプリケーションを持っています。 209ファイルを正常にアップロードした後は、サイズが7.8kbのファイルでエラーが発生しました。そのサイズはWhile Processing Img1.jpg Unable to write data to the transport connection. An existing connection was forcibly closed by the remote hostです。Ftpアップロードで例外が発生しましたトランスポート接続にデータを書き込めません。既存の接続はリモートホストによって強制的に閉じられました

string uri1; 

ftpInfoUpload = LoadHostedSiteData(hs); 
ftpInfoUpload[5] = imgRow["Filename"].ToString(); 

uri1 = String.Format("ftp://{0}/{1}/images/{2}", ftpInfoUpload[1], ftpInfoUpload[2], ftpInfoUpload[5]); 

requestUpload = (FtpWebRequest)WebRequest.Create(uri1); 
requestUpload.UsePassive = false; 
requestUpload.UseBinary = true; 
requestUpload.Method = WebRequestMethods.Ftp.UploadFile; 
requestUpload.Credentials = new NetworkCredential(ftpInfoUpload[3], ftpInfoUpload[4]); 


requestUpload.ContentLength = memStream.Length; 
byte[] buff = new byte[bufferSize]; 
int contentLen; 

// Stream to which the file to be upload is written 
Stream strm = requestUpload.GetRequestStream(); 
memStream.Seek(0, SeekOrigin.Begin); 
contentLen = memStream.Read(buff, 0, bufferSize); 
          // Till Stream content ends 
while (contentLen > 0) 
{ 
    // Write Content from the file stream to the FTP Upload Stream 
    strm.Write(buff, 0, contentLen); 
    contentLen = memStream.Read(buff, 0, bufferSize); 
} 

//Close the file stream and the Request Stream 
strm.Close(); 
strm.Dispose(); 
ftpStream.Close(); 
memStream.Close(); 
//responseUpload.Close(); 
responseDownload.Close(); 

アイデアは何が起こっていますか?

+0

FTPサーバーのクォータを超過したため、接続が中断された可能性があります。サポートについては、サーバー管理者にお問い合わせください。 –

+0

@HansPassantファイル数のクォータ?サーバーにはユーザーが転送できるファイル数の割り当てがありますか? – PUG

+0

おそらくありません。むしろ、あなたがアップロードしたファイルのサイズに応じて発生したトラフィックの総量に対するクォータまたは単純な接続のリセット – yas4891

答えて

1

私はftprequest.KeepAlive=true &セットftprequest.ConnectionGroupName = "Some Value"を設定しました。そのため、基礎となるコードは、同じFTPサーバーを持つ新しい作成接続を必要としません。私はこの解決策を見つけたhere。私はまた、thisが役に立ちました。また、例外を引き起こす可能性のあるファイルを転送するたびに、新しいNetworkCredentialオブジェクトを作成しないようにしてください。私は自分のコードを300回のファイル転送を2回テストしており、完璧かつ迅速に動作するようです。 KeepAlive=falseを設定すると、転送が遅くなる可能性があります。

関連する問題