I use Tamir.SharpSSH library to make my SFTP operations. I can upload file from client, delete or list files located in an SFTP server directory.
But I cannot find how to append a text file. I don't want to overwrite or delete the existing and upload a new one. I have a log file on that SFTP server. I have to add new lines to that file from client side.
I just searched the internet and looked different functions in the code but tried nothing to execute because I could not find anything till now.
Thanks in advance
EDIT
I decided to use Renci.SshNet library because of @Martin Prikryl's advise. I tried the above operations with that library also and I saw it works good. Also appending text to a text file is very simple with that library. I'm sharing a small example about that here:
using System
using Renci.SshNet;
namespace SFTPConnectSample
{
class Program
{
static void Main(string[] args)
{
AppendText(@"/targetFolder/targetFile.txt");
}
private static void AppendText(string targetFilePath)
{
int portNumber = 22;
using (SftpClient sftp = new SftpClient("myHostName", portNumber, "sftpUser", "sftpPassword"))
{
sftp.ConnectionInfo.Timeout = new TimeSpan(0, 0, 30);
sftp.Connect();
sftp.AppendAllText(targetFilePath, "\r\nThis is a new line for target text file.");
}
}
}
}