1
我想動態生成文件並將該文件保存在FTP文件夾位置如何直接在FTP文件夾上創建並保存文件?
我試過像下面這樣。 我不想在本地保存文件,然後將其上傳到FTP位置。
我有流並希望使用該流在ftp上創建文件。
我該怎麼做?
FtpWebRequest requestFileUpload = (FtpWebRequest)WebRequest.Create("ftp://" +ftpServerIP+ "/" + remoteDir);
requestFileUpload.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
requestFileUpload.Method = WebRequestMethods.Ftp.UploadFile;
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(FILEDATA);
//FILEDATA is nothing but string
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
requestFileUpload.ContentLength = fileContents.Length;
Stream requestStream = requestFileUpload.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)requestFileUpload.GetResponse();
response.Close();