I am connecting to an SFTP connection via the terminal. I want to download a file.
If I go to the folder, I can list the contents:
lsI can clearly see the file; let's call it "my_file.csv".
If I try this code:
sftp get my_file.csvI get this error:
Connecting to get...
ssh: Could not resolve hostname get: Name or service not known
Couldn't read packet: Connection reset by peerI can view the file with "less my_file.csv". It is clearly there and accessible, but I cannot download it with any combination of sftp get that I try (I have tried lots of options). I've also tried using curl but no luck.
If I type SFTP, I do get options:
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config] [-o ssh_option] [-P sftp_server_path] [-R num_requests] [-S program] [-s subsystem | sftp_server] host sftp [user@]host[:file ...] sftp [user@]host[:dir[/]] sftp -b batchfile [user@]hostAny help is appreciated! I am setting this up to download the file on a schedule ultimately (e.g., every hour).
11 Answer
sftp wants the host as the first argument. So, if you form the argument like so:
sftp user@host:my_file.csv, it should work. With your command, sftp wrongly assumes that the hostname is get.
You can also add a path if you want to access other than the default for the sftp command on the server: sftp user@host:/path/to/my_file.csv.
sftp is more suited to interactive usage. For your purpose, as pointed out by @Jos, scp would be a better fit.