如何在sftp服务器中创建文件。 (c#console应用程序) [英] How can I create a file in a sftp server. (c# console application)

查看:122
本文介绍了如何在sftp服务器中创建文件。 (c#console应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的sftp服务器中创建一个文件,但我不知道请求有多帮助。

I would like to create a file inside of my sftp server, but I don't know how pleas help.

我已经可以将文件上传到服务器了,但是这个文件必须是本地的。我不希望我想在服务器中直接创建我的文件。

I already can upload file's to the server, but this file's have to be local. I don't want that I want to directly create my files in the server.

推荐答案

你好N0rdin,

Hi N0rdin,

我们可以将内容写入MemoryStream并将Stream上传到Sftp Server。这是一个简单的示例供您参考。

We could write the content to MemoryStream and upload the Stream to Sftp Server. here is a simple sample for your reference.

string host = "host";
int port = 0;//your port
string username = "username";
string password = "pwd";
var client = new SftpClient(host, port, username, password);
client.Connect();
string content = "Test";
byte[] results = Encoding.ASCII.GetBytes(content);
var stream = new MemoryStream();
stream.Write(results, 0, results.Length);
stream.Position = 0;
client.UploadFile(stream, "/remote/path/my.pdf");

致以最诚挚的问候,

张龙


这篇关于如何在sftp服务器中创建文件。 (c#console应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆