The issue was I needed to append the intended file name on the remote directory like so:
The same is true for renaming files, both strings will need the full path and file name:
public bool UploadFile(Settings settings, string localPath, string fileName)
{
try
{
using (var sftp = new SftpClient(settings.Host, settings.Username, settings.Password))
{
sftp.Connect();
using (var fileStream = File.OpenRead(localPath))
{
var remotePath = settings.RemoteDirectory + fileName;
sftp.UploadFile(fileStream, remotePath, true);
}
sftp.Disconnect();
}
return true;
}
catch (Exception ex)
{
Utility.Err(ex, "UploadFile()");
return false;
}
}
Now i just pass in the filename, and append it to the remote directoryThe same is true for renaming files, both strings will need the full path and file name:
public bool RenameRemoteFile(Settings settings, string oldFilePath, string newFilePath)
{
try
{
using (var sftp = new SftpClient(settings.Host, settings.Username, settings.Password))
{
sftp.Connect();
sftp.RenameFile(oldFilePath, newFilePath);
sftp.Disconnect();
}
return true;
}
catch (Exception ex)
{
Utility.Err(ex, "RenameRemoteFile()");
return false;
}
}