Change current working directory with TScSFTPClient ...

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
pfrossard
Posts: 19
Joined: Thu 08 Apr 2010 09:25

Change current working directory with TScSFTPClient ...

Post by pfrossard » Tue 01 Jun 2010 22:49

Hi,
After the connexion to an SFTPServer,
How to change the current working directory with TScSFTPClient ?
I don't find this function !?
Thanks.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 02 Jun 2010 08:48

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.

pfrossard
Posts: 19
Joined: Thu 08 Apr 2010 09:25

Post by pfrossard » Wed 02 Jun 2010 08:54

We can not do a "cd /etc" with your SFTPClient ?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 02 Jun 2010 10:04

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('..');

wishknew
Posts: 1
Joined: Tue 14 Jan 2020 11:33

Re: Change current working directory with TScSFTPClient ...

Post by wishknew » Mon 05 Jul 2021 08:04

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?

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: Change current working directory with TScSFTPClient ...

Post by YanishevskiyVI » Tue 06 Jul 2021 13:03

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

Post Reply