久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從字符串或流上傳文件到 FTP 服務器

Upload a file to an FTP server from a string or stream(從字符串或流上傳文件到 FTP 服務器)
本文介紹了從字符串或流上傳文件到 FTP 服務器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試在 FTP 服務器上創建一個文件,但我所擁有的只是一個字符串或數據流以及創建它時應使用的文件名.有沒有辦法從流或字符串在服務器上創建文件(我沒有創建本地文件的權限)?

I'm trying to create a file on an FTP server, but all I have is either a string or a stream of the data and the filename it should be created with. Is there a way to create the file on the server (I don't have permission to create local files) from a stream or string?

string location = "ftp://xxx.xxx.xxx.xxx:21/TestLocation/Test.csv";

WebRequest ftpRequest = WebRequest.Create(location);
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.Credentials = new NetworkCredential(userName, password);

string data = csv.getData();
MemoryStream stream = csv.getStream();

//Magic

using (var response = (FtpWebResponse)ftpRequest.GetResponse()) { }

推薦答案

只需將你的流復制到 FTP 請求流:

Just copy your stream to the FTP request stream:

Stream requestStream = ftpRequest.GetRequestStream();
stream.CopyTo(requestStream);
requestStream.Close();


對于一個字符串(假設內容是一個文本):


For a string (assuming the contents is a text):

byte[] bytes = Encoding.UTF8.GetBytes(data);

using (Stream requestStream = request.GetRequestStream())
{
    requestStream.Write(bytes, 0, bytes.Length);
}

或者甚至更好地使用 StreamWriter:

Or even better use the StreamWriter:

using (Stream requestStream = request.GetRequestStream())
using (StreamWriter writer = new StreamWriter(requestStream, Encoding.UTF8))
{
    writer.Write(data);
}

如果內容是文本,則應使用文本模式:

If the contents is a text, you should use the text mode:

request.UseBinary = false;

這篇關于從字符串或流上傳文件到 FTP 服務器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 九九视频在线 | 天天干干干 | 免费成年人视频 | 精品国产福利 | 日本一级淫片 | 国产日韩欧美综合 | a毛片视频| 精品小视频 | 久久久久成人网 | 久久a级片 | 亚洲日本一区二区 | 在线播放a | 国产精品二区一区二区aⅴ污介绍 | 国产理论视频 | 成人一级毛片 | 亚洲视频网 | 中文字幕亚洲天堂 | 久久最新视频 | 久久久久亚洲 | 日韩免费小视频 | 亚洲人天堂| 欧美色偷偷 | 国产福利视频 | 黄色成人在线 | 国产美女毛片 | 一级黄色片在线观看 | 日韩欧美在线观看 | 日韩专区在线观看 | 一级黄色片免费 | 国产福利小视频 | 精品国产99久久久久久宅男i | 亚久久 | 好好的日com | 美女91网站| 91免费福利视频 | www.日本在线 | 天天射日日干 | 久久人人视频 | 国产乱码精品一区二区三 | 玖草在线 | 午夜两性|