Understanding SFTP Absolute FilePaths

Given that your SFTP client might be communicating with servers on different operating systems, what is the proper syntax for an absolute filepath? On a Linux system, there is no “C” drive. Let’s do some experimentation….

For this experiment, we have two SSH servers:
1) A Tectia server running on a Windows platform.
2) An OpenSSH server running on Ubuntu Linux.

To begin, call RealPath(“.”) to determine the absolute path of the home directory for the SSH user account. Here’s are the results:

1) On Tectia server we have a Windows account named “test123”. Calling RealPath(“.”) results in this filepath:
/C/Documents and Settings/test123

2) On the OpenSSH server, the Linux user account is named “chilkat”. RealPath(“.”) returns this:
/home/chilkat

If your application passes an absolute filepath to an SFTP method (such as RemoveFile), it must use a filepath that conforms to the requirements of the server operating system. For example, to delete a file on a Linux server, you might do this:

bool success = sftpObject.RemoveFile("/tmp/junk.txt");

To delete a file on a Windows server, you would need to include the drive letter, like this:

bool success = sftpObject.RemoveFile("/C/temp/junk.txt");
Tags :