login about faq

How can I change the directory in SFTP?

asked Jun 17 '14 at 10:50

chilkat's gravatar image

chilkat ♦♦
11.8k316358420


The SFTP protocol (Secure File Transfer over SSH) is a protocol that has no relation to FTP -- other than the fact that both do file transfer (but so does HTTP, and nobody would confuse HTTP with FTP, nor would anyone ask how to change the directory in HTTP).

The confusion often arises because applications such as FileZilla will offer a UI that is the same for both SSH/SFTP and for FTP. When you "change the remote directory" in Filezilla w/ an SFTP server, FileZilla is not sending a "change directory" command to the SSH/SFTP server -- because none exists in that protocol and there is not "current working directory" for your session. In SFTP, your "current directory" is always the HOME directory of your SSH user account.

Let's say you "change the directory" in FileZilla to subdirA. What FileZilla does is to note that you are now logically "in subDirA", it will retrieve the directory listing for subdirA and display it for you. If you choose to download a file, such as "zebra.txt", what FileZilla really does is, noting that you are logically in subDirA and that the files you are currently viewing are from subDirA, it will send a request to download "subdirA/zebra.txt". Internally, FileZilla is concatenating what you see as your "current directory" with the filename you are choosing to upload or download.

You, as the application developer, are working with the SFTP protocol. Given that there is no state, meaning you are never "in a current directory", the filepaths you provide must be either relative from the HOME directory of the SSH user account, or an absolute filepath (meaning absolute from the root of the remote filesystem).

link

answered Jun 17 '14 at 10:59

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

As far as I know, the SFTP protocol doesn't have any notion of a "current directory". You always need full paths.

link

answered Jun 17 '14 at 10:51

Gert's gravatar image

Gert ♦
629141824

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×200
×10
×3

Asked: Jun 17 '14 at 10:50

Seen: 1,229 times

Last updated: Jun 17 '14 at 10:59

powered by OSQA