Page 1 of 1

Change current working directory with TScSFTPClient ...

Posted: Tue 01 Jun 2010 22:49
by pfrossard
Hi,
After the connexion to an SFTPServer,
How to change the current working directory with TScSFTPClient ?
I don't find this function !?
Thanks.

Posted: Wed 02 Jun 2010 08:48
by Dimon
In SFTP protocol the "current working directory" concept doesn't exist. You can open a directory using the OpenDirectory method, and you can get an absolute path to any directory using the RetrieveAbsolutePath method.
You can look at the example of working with SFTP client using the SFTPClient demo.

Posted: Wed 02 Jun 2010 08:54
by pfrossard
We can not do a "cd /etc" with your SFTPClient ?

Posted: Wed 02 Jun 2010 10:04
by Dimon
You can do it by calling the OpenDirectory method with the needed path. For example, to get files list of the root directory (like cd ..) just execute the folowing code:
SFTPClient.OpenDirectory('..');

Re: Change current working directory with TScSFTPClient ...

Posted: Mon 05 Jul 2021 08:04
by wishknew
I would like to upload a text file in a Testing folder in the remote server.

This following code works well.

Code: Select all

sftp.OpenDirectory('Testing');
sftp.RetrieveAbsolutePath('Testing', rcNoCheck, list);
sftp.UploadFile('c:\temp\test.txt', 'Testing\test.txt', True);
Without calling RetrieveAbsolutePath after OpenDirectory the UploadFile will be failed. Is this really the behaviour?

Re: Change current working directory with TScSFTPClient ...

Posted: Tue 06 Jul 2021 13:03
by YanishevskiyVI
Hi There,

In fact, no.

The RetrieveAbsolutePath, OpenDirectory and UploadFile methods is not modal, therefor they should NOT depend on each other. Thus, they can be called in any sequence, and it should not cause any fails.

Since you only need to upload a file, it’s enough to call only:

Code: Select all

ScSFTPClient.UploadFile([localpath\filename], [ftpserverpath\filename], True) 
Regards,
Vitaliy