Answer the question
In order to leave comments, you need to log in
How to upload a file via ftp if the host is Linux?
The site is on Asp.Net Core 3.1, people upload files to the site, these files need to be saved to FTP.
FtpWebRequest is used for downloading, Stream is created like this:
public Stream GetUploadStream(string filePath)
{
var request = (FtpWebRequest)WebRequest.Create(_ftp.Server + filePath);
request.Credentials = _credential;
request.EnableSsl = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
return request.GetRequestStream();
}
// file - IFormFile из multipart form
var requestStream = ftp.GetUploadStream(filePath);
await file.OpenReadStream().CopyToAsync(requestStream);
requestStream.Close();
Message = The remote server returned an error: (550) File unavailable (eg, file not found, no access).
550 read tcp ip:port-\u003Eip:port: read: connection reset by peer\r\n
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question