Я пытаюсь загрузить файл XML на SFTP-сервер, используя S SH. NET. (.NetCore 3.1 / VS 2019 / C#)
Путь к удаленной папке для загрузки файла - «/ testin /», что подтверждает, что у нас достаточно разрешения на запись для загрузки файлов в эту папку. Я могу подключиться и авторизоваться на SFTP-сервере по этому соединению. Тем не менее, когда я пытаюсь загрузить файл, S SH. net возвращает только «Сбой» в сообщении об исключении без других четких подробностей. Я могу скачивать файлы без проблем. Проверяя сводные данные функции «Загрузка» из S SH. NET, как показано ниже, она указывает, что она вернет четкое сообщение об ошибке для разрешений и так далее. Я провел поиск по inte rnet без особого успеха.
// Summary:
// Uploads stream into remote file.
//
// Parameters:
// input:
// Data input stream.
//
// path:
// Remote file path.
//
// canOverride:
// if set to true then existing file will be overwritten.
//
// uploadCallback:
// The upload callback.
//
// Exceptions:
// T:System.ArgumentNullException:
// input is null.
//
// T:System.ArgumentException:
// path is null or contains only whitespace characters.
//
// T:Renci.SshNet.Common.SshConnectionException:
// Client is not connected.
//
// T:Renci.SshNet.Common.SftpPermissionDeniedException:
// Permission to upload the file was denied by the remote host.
// -or-
// A SSH command was denied by the server.
//
// T:Renci.SshNet.Common.SshException:
// A SSH error where System.Exception.Message is the message from the remote host.
//
// T:System.ObjectDisposedException:
// The method was called after the client was disposed.
//
// Remarks:
// Method calls made by this method to input, may under certain conditions result
// in exceptions thrown by the stream.
public void UploadFile(Stream input, string path, bool canOverride, Action<ulong> uploadCallback = null);
Вот мой код: Есть идеи?
using (var sftp = new SftpClient(Host, TcpPort, Username, Password))
{
try
{
sftp.Connect();
var localFile = Path.Combine(LocalUploadPath + LocalFilename);
// var path = $"{localFile.Replace(@"\", "/")}";
using (var fs = File.OpenRead(localFile))
{
sftp.UploadFile(fs, RemoteUploadRootPath, true);
}
}
catch (Exception ex)
{
sftp.Disconnect();
throw new Exception($"{ex.Message} {ex.InnerException}"
}
finally
{
sftp.Disconnect();
}
}
![enter image description here](https://i.stack.imgur.com/4ntrr.jpg)