Remote server change directory

Advertisement

Cadel
Joined:
Posts:
3
Location:
United States

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();
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,802
Location:
Prague, Czechia

Re: Remote server change directory

Cadel wrote:

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.
No it's not. As you have specified an absolute path as /root/b/filename.rec, WinSCP is uploading exactly there. The home path (/root/A) is not involved at all.
Can you upload the file using WinSCP GUI?

Reply with quote

Cadel
Joined:
Posts:
3
Location:
United States

Yes, using WinSCP application, I am able to get to root/B folder, and save file to root/B folder. When I login using WinSCP application the root/A folder is shown, then I click on the icon in the toolbar, "Parent directory" the folder with the up arrow, and then I'm in the parent folder and can see folder A and folder B. I double click folder B, then upload my file to folder B.
The account on the server defaults to root/A folder. I asked the admin to default my user account to folder B and she said "No".

So, in my code how do I change the directory? Currently my code appends folder B to folder A. So it looks like this "root/A/root/B/filename" I want just "root/B/filename".

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,802
Location:
Prague, Czechia

Re: Found the answer

sy_christine wrote:

I ran into the same issue as you. Could you please kindly elaborate on how you solved this issue? I don't find the above Stackoverflow link helpful.
It would help, if your actually elaborate on your problem and share some logs.

Reply with quote

Advertisement

You can post new topics in this forum