如何在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");

致以最诚挚的问候,

张龙