31

I thought I was familiar with sftp commands in unix and upto my knowledge the command to used to download a compressed file from the server is

sftp get filename.tar.gz

But when I tried this command the file gets emptied, I mean the file size is going 0 and I don't know why it happens. Is there any other command specifically for .tar.gz type of files. What is the procedure to get this compressed files. I'm using mac terminal.

2
  • 2
    Don't you have to include the server address? What is the exact command you typed? Nov 11, 2014 at 6:58
  • @FaheemMitha I've entered into server using sftp command. sftp user[at]server and in the sftp terminal I used > get filename.tar.gz
    – GIRI
    Nov 11, 2014 at 16:13

2 Answers 2

61

get is a legal sftp command, but can't be used that way.

The correct syntax to download filename.tar.gz to your Mac is:

sftp user@host:/path/to/filename.tar.gz /some/local/folder

(Replace user with the user you use to connect to the remote server, replace host with the remote server name.)

There's nothing special to tar.gz files in the above command, it is generic to any extension.

To use get you have to enter interactive mode first:

  1. Make a connection to the remote server:

    sftp user@host
    

    Wait until >, the sftp prompt, appears in a newline - you can now type your commands.

  2. Change the remote path to /path/to:

    cd /path/to/
    
  3. Change the local path to /some/local/folder:

    lcd /some/local/folder
    
  4. Use get to download the file:

    get filename.tar.gz
    
6
  • No, its not working I tried your suggestions. tried changing the local paths but no effect.
    – GIRI
    Nov 11, 2014 at 16:09
  • Could you post the output of the sftp command?
    – jaume
    Nov 11, 2014 at 18:33
  • There is no such output kind of thing, as type sftp > get filename.tar.gz the file doesn't gets downloaded and the memory turns to be 0.
    – GIRI
    Nov 13, 2014 at 4:00
  • Neither sftp > get filename.tar.gz nor, as posted in your question, sftp get filename.tar.gz will work. The correct syntax is sftp user@host:/path/to/filename.tar.gz /some/local/folder, as explained in my answer. What happens when you type the command (replace user, host, /path/to and /some/local/folder with values that are correct in your environment) in Terminal and then press Enter? Is there any output? If so, please add it to our question.
    – jaume
    Nov 14, 2014 at 10:10
  • There is NO output. it just goes to next line.
    – GIRI
    Nov 14, 2014 at 23:39
3

Here another way if you are already logged into the the sftp session.

If you do a get:

sftp> get my-file.txt
get: failed to download /home/user/my-file.txt. Access is denied. 

You may considere if locally you have the permissions to write. To check where the file will be downloaded do:

sftp> lpwd
C:\Users\user1\Documents

Generally "Documents" is not permissive. So, change the download dir to C:\tmp:

sftp> lcd C:\tmp
sftp> get my-file.txt
    Downloading my-file.txt from /home/user/my-file.txt
    1% 437123KB    620KB/s 00:00:41 ETA

Done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .