我正在尝试将图像上传到FTP服务器。但是我遇到了错误
远程服务器返回错误:(550)文件不可用(例如,文件未找到,无法访问)。
这是我的代码:
public void Upload(string fileName,string base64,string path)
{
var bytes = Convert.FromBase64String(base64);
var uri = new Uri($"ftp://{Host}/{path}/{fileName}");
var request = (FtpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = false;
request.Credentials = new NetworkCredential(username,Password);
request.ContentLength = bytes.Length;
request.UseBinary = true;
request.KeepAlive = false;
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(bytes,bytes.Length);
requestStream.Close();
}
using (var response = (Ftpwebresponse)request.GetResponse())
{
if (response != null)
response.Close();
}
}
我的Host
是这样的:localhost:port-number
。
该路径是一个名为Images
的文件夹。
所以我想将图像保存在localhost:port-number/Images
处,但出现此错误。
当我从浏览器中打开FTP点时,它可以正常工作,并且可以看到内容。怎么了?