EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SFTP Changing Directory

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
Posted: 02/22/2010 16:12:54
by Tim Molloy (Standard support level)
Joined: 11/13/2009
Posts: 21

My utility requires me to change the directory out of the current parent. I've tried many variations of OpenDirectory and RequestAbsolutePath, but keep getting the same error over and over again "SBSftpCommon.EElSFTPError: No such file".

When using FileZilla, I land in an empty dir called 'FTHS0201.'

I've been instructed to use the CWD command to go to 'FTFTHS02.'

I'm trying to figure out the equivalent of this using ElSimpleSFTPClient.

here's the code:
                    currentDir = @"FTFTHS02";
                    _logger.InfoFormat("1: Changing directory to: {0}", currentDir);
                    dirHandle = sftpClient.OpenDirectory(AbsPath(".", currentDir));
                    _logger.InfoFormat("1: Trying to request the absolute path to {0}", currentDir);
                    currentDir = sftpClient.RequestAbsolutePath(AbsPath(".", currentDir));
                    //remoteFilePath = Path.Combine(currentDir, remoteFileName);
                    //_logger.InfoFormat("1: Uploading file {0} as {1} to {2}.", localFilePath, remoteFileName, currentDir);
                    //sftpClient.UploadFile(localFilePath, remoteFilePath, TSBSFTPFileTransferMode.ftmOverwrite);
                catch (Exception ex)
                    _logger.Error("error 1");
                    _logger.ErrorFormat("Error: {0} | {1}", ex.Message, ex);

        // helper function to form full path
        public string AbsPath(string currentDir, string strFileName)
            string strResult = "";

            if ((currentDir.Length == 0) || (currentDir[currentDir.Length - 1] != '\\' && currentDir[currentDir.Length - 1] != '/'))
                strResult = currentDir + '/' + strFileName;
            else strResult = currentDir + strFileName;

            _logger.InfoFormat("AbsPath: {0}", strResult);
            return strResult;
Posted: 02/22/2010 17:59:53
by Tim Molloy (Standard support level)
Joined: 11/13/2009
Posts: 21

Basically, I'm having trouble getting the absolute path here. I've tried so many variations, it's hard to keep track:


getting the error in all cases.
Posted: 02/23/2010 00:21:37
by Eugene Mayevski (EldoS Corp.)

SFTP doesn't have a concept of current directory, and so you can't change as for requesting the absolute path, it's possible that the server doesn't let you do this.

Also, to get further support please assign the license ticket to your user account. The instructions can be found in the registration e-mail.

Sincerely yours
Eugene Mayevski
Posted: 02/24/2010 12:07:34
by Tim Molloy (Standard support level)
Joined: 11/13/2009
Posts: 21

Eugene, I cannot locate my "license ticket". Our IT guy ordered the software and he did so through a third-party. The order number was 303427325. Or do you mean the license key?

Anyway, I don't necessarily need to do the OpenDirectory, I just need to drop my file in a different location. If I were to use Windows ftp.exe, I would create a cmd script as follows:

cd 'FTFTHS02.'
put c:/sourcefile.txt destinationfile.txt

So far, this is what is implemented, but I want to use SBB. How do I go about getting the absolute path of the directory I am changing to above?
Posted: 02/24/2010 13:45:18
by Eugene Mayevski (EldoS Corp.)

Licensing-related question has been moved to HelpDesk.

Tim Molloy wrote:
Anyway, I don't necessarily need to do the OpenDirectory, I just need to drop my file in a different location. If I were to use Windows ftp.exe, I would create a cmd script as follows:

As said, there's no "current" directory in SFTP, so "cd" command has no equivalent.

Did you try putting the file directly to "/FTFTHS02" (with leading slash or whatever symbol is used as a path separator on the remote syste) instead of gettnig the absolute directory?

Sincerely yours
Eugene Mayevski
Posted: 05/19/2010 06:08:17
by miguel erill (Standard support level)
Joined: 05/10/2010
Posts: 3

Hi Eugene.

May the RFC not define the concept of "current" directory for SFTP but the fact is that most of SFTP servers there about accept it and they respond to the 'cd path' command, actually changing the directory to the given path.

So it will be of great use to have a function to change the path in the server. This function could check if the server reply has 'invalid command' in it to fire the onError procedure. This will ease all our lives.

Posted: 05/19/2010 07:43:33
by Eugene Mayevski (EldoS Corp.)

I am sorry but the statement of "respond to "cd path" command doesn't make much sense because SFTP uses binary command codes. And neither path change nor path retrieval commands are defined. So whatever you see in other application's log is just an emulation for human readability.

Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.



Topic viewed 3483 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!