Remote server change directory
C# WinSCP code logs into remote server and puts me in root/A folder. I want to go to folder root/B folder. How do I upload a file to root/B folder?
Code works to login, just can't get to the correct folder. When I run the code below, I get error: Cannot create remote file, no such file or directory. I'm sure it is trying to append to the root/A folder and I need it to go one step up to root then go to B folder.
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = sftpHost,
UserName = sftpUsername,
Password = sftpPassword,
SshHostKeyFingerprint = "ssh-rsa ...",
SshPrivateKeyPath = @"P:\...",
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.PutFiles(strFileName, "/root/b/filename.rec", false, transferOptions);
// Throw on any error
transferResult.Check();
}
Code works to login, just can't get to the correct folder. When I run the code below, I get error: Cannot create remote file, no such file or directory. I'm sure it is trying to append to the root/A folder and I need it to go one step up to root then go to B folder.
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = sftpHost,
UserName = sftpUsername,
Password = sftpPassword,
SshHostKeyFingerprint = "ssh-rsa ...",
SshPrivateKeyPath = @"P:\...",
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.PutFiles(strFileName, "/root/b/filename.rec", false, transferOptions);
// Throw on any error
transferResult.Check();
}