5
我在C#2015中使用SSH.NET。SSH.NET上传整个文件夹
使用此方法,我可以上传文件到我的SFTP服务器。
public void upload()
{
const int port = 22;
const string host = "*****";
const string username = "*****";
const string password = "*****";
const string workingdirectory = "*****";
string uploadfolder = @"C:\test\file.txt";
Console.WriteLine("Creating client and connecting");
using (var client = new SftpClient(host, port, username, password))
{
client.Connect();
Console.WriteLine("Connected to {0}", host);
client.ChangeDirectory(workingdirectory);
Console.WriteLine("Changed directory to {0}", workingdirectory);
using (var fileStream = new FileStream(uploadfolder, FileMode.Open))
{
Console.WriteLine("Uploading {0} ({1:N0} bytes)",
uploadfolder, fileStream.Length);
client.BufferSize = 4 * 1024; // bypass Payload error large files
client.UploadFile(fileStream, Path.GetFileName(uploadfolder));
}
}
}
这对于一个单独的文件完美的作品。现在我想上传整个文件夹/目录。
现在有人该怎么做到这一点?
好的,也许你可以给我一个关于如何“递归到子目录”的例子吗? – Francis
查看我的更新回答。 –
节省我的时间很棒thx。 –