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

從字符串或流上傳文件到 FTP 服務(wù)器

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

問題描述

限時送ChatGPT賬號..

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

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()) { }

推薦答案

只需將你的流復(fù)制到 FTP 請求流:

Just copy your stream to the FTP request stream:

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


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


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);
}

如果內(nèi)容是文本,則應(yīng)使用文本模式:

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

request.UseBinary = false;

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

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

相關(guān)文檔推薦

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 令牌授權(quán)不起作用)
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(如何獲取守護進程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
.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(異步調(diào)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 久久午夜精品福利一区二区 | 青青草亚洲 | 午夜一级黄色片 | 国产欧美精品区一区二区三区 | 亚洲精品68久久久一区 | 伊人二区 | 日韩在线观看一区 | 亚洲www啪成人一区二区麻豆 | 老头搡老女人毛片视频在线看 | 中文字幕啪啪 | 国产一区在线免费观看 | 欧美男人天堂 | 国产精品成av人在线视午夜片 | 亚洲人成免费 | 成人乱人乱一区二区三区软件 | 亚洲精品福利在线 | 亚洲一区 中文字幕 | 夜夜摸天天操 | 欧美成人免费 | 色综合视频在线 | 国产农村妇女精品一二区 | 国产精品视频999 | 中文字幕精品一区二区三区精品 | 青青草这里只有精品 | 亚洲一区二区精品视频在线观看 | 欧美久久一区二区三区 | 久久久不卡网国产精品一区 | 99热这里都是精品 | 欧美久久久久久久久 | 国产亚洲一区二区精品 | 二区欧美| 国产日韩欧美 | 国产高清在线 | 精品亚洲永久免费精品 | 久久久久久高潮国产精品视 | 99久久久久久久 | 一区二区三区国产 | 一区二区三区日韩 | 日韩在线欧美 | 精品一区二区三区电影 | 999久久久 |