![](/img/trans.png)
[英]c# Upload local file to Server using FTP. The c# files are on hosted on the server
[英]FTP file upload on Local Network C#
我在FTP服務器上傳文件時遇到問題。 當我在我的計算機(127.0.0.1)上運行FileZilla服務器時,圖像文件已成功上載。 但我在同一網絡中的另一台計算機上運行FileZilla服務器。(10.0.1.25)。 我可以在這台計算機上創建目錄,但我無法上傳圖像文件,盡管我的用戶可以完全控制這台計算機。
public bool Upload(Stream srcStream, string dstFilePath)
{
Create FtpWebRequest object from the Uri provided
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(serverUri + dstFilePath));
reqFTP.Credentials = credential;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
reqFTP.KeepAlive = false;
reqFTP.ContentLength = srcStream.Length;
byte[] buff = new byte[UPLOAD_DOWNLOAD_BUFFER_SIZE];
int contentLen;
// Stream to which the file to be upload is written
using (Stream dstStream = reqFTP.GetRequestStream())
{
// Read from the file stream 2kb at a time
contentLen = srcStream.Read(buff, 0, UPLOAD_DOWNLOAD_BUFFER_SIZE);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
dstStream.Write(buff, 0, contentLen);
contentLen = srcStream.Read(buff, 0, UPLOAD_DOWNLOAD_BUFFER_SIZE);
}
dstStream.Close();
}
}
// Get the response to the upload request.
bool ret;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
// ret = (response.StatusCode == FtpStatusCode.ClosingData); //
response.Close();
ret = (GetFileSize(dstFilePath) == srcStream.Length);
return ret;
}
當我將第9行更改為reqFTP.UsePassive = true時,服務器返回(227進入被動模式(h1,h2,h3,h4,p1,p2))。 現在它返回(500)語法錯誤,命令無法識別。 會有什么問題? 謝謝
我可以在防病毒運行時上傳圖像Filezilla。 但是,當我通過使用我的代碼塊嘗試它。 它返回端口錯誤消息。 防病毒停止后,一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.