【发布时间】:2014-07-14 10:20:19
【问题描述】:
我想动态生成文件并将该文件保存在 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();
【问题讨论】:
标签: c# csv ftp c#-3.0 ftpwebrequest