How to download a file from server using SSH?
In your terminal, type:
scp your_username@remotehost.edu:foobar.txt /local/dir
replacing the username, host, remote filename, and local directory as appropriate.
If you want to access EC2 (or other service that requires authenticating with a private key), use the -i
option:
scp -i key_file.pem your_username@remotehost.edu:/remote/dir/foobar.txt /local/dir
From: http://www.hypexr.org/linux_scp_help.php
Copying files from server to local computer using SSH
It depends on what your local OS is.
If your local OS is Unix-like, then try:
scp username@remoteHost:/remote/dir/file.txt /local/dir/
If your local OS is Windows ,then you should use pscp.exe
utility.
For example, below command will download file.txt from remote to D:
disk of local machine.
pscp.exe username@remoteHost:/remote/dir/file.txt d:\
It seems your Local OS is Unix, so try the former one.
For those who don't know what pscp.exe
is and don't know where it is, you can always go to putty
official website to download it. And then open a CMD prompt, go to the pscp.exe directory where you put it. Then execute the command as provided above
EDIT
if you are using Windows OS above Windows 10, then you can use scp
directly from its terminal, just like how Unix-like OS does.
Thanks to @gijswijs @jaunt @icanfathom
Download file to local computer via SCP while ssh connection to remote computer
Instead of
scp username@host : /path/to/hosts/file/host_file.txt ~/desktop
remove the spaces surrounding the :
.
scp username@host:/path/to/hosts/file/host_file.txt ~/desktop
Edit:
I keep getting an error when trying to download a file from a remote computer when connected via SSH.
You shouldn't run the scp command when you are already sshed into the server --- that just downloads the file from the server... to the server.
You should run the scp command directly from your mac.
Download a file remote server that uses different port and private key
scp -i private_key.pem -P 2222 username@ip_address:/backup/file.zip .
This worked for me.
How to download file(s) from remote server directory to local machine in PuTTY?
(Question is probably more suited to Superuser)
You have your parameters in the wrong order. Please refer to the documentation:
https://the.earth.li/~sgtatham/putty/0.70/htmldoc/Chapter5.html#pscp
To download, you need:
pscp [options] [user@]host:source target
What you have there is the opposite, it's for doing an upload.
Download file using ssh with simple-ssh npm
Try to get first only the files that are in your folders without using variables, using your path as a string to eliminate errors.
var Client = require('ssh2-sftp-client');
let sftp = new Client
sftp.connect({
host: 'remote_server_iṕ',
port: 22,
username: 'username',
password: 'password'
}).then(() => {
return sftp.list('/');
}).then(async (files) => {
console.log(files);
len = files.length;
await files.forEach(x => {
let remoteFilePath = '/' + x.name;
sftp.get(remoteFilePath).then((stream) => {
let file = './ftp/' + x.name;
fs.writeFile(file, stream, (err) => {
if (err) console.log(err);
});
});
});
}).catch((err) => {
console.log(err, 'catch error');
});
To get a single file:
var Client = require('ssh2-sftp-client');
let sftp = new Client
sftp.connect({
host: 'remote_server_iṕ',
port: 22,
username: 'username',
password: 'password'
}).then(() => {
let remoteFilePath = '/' + fileName;
sftp.get(remoteFilePath).then((stream) => {
let file = './ftp/' + x.name;
fs.writeFile(file, stream, (err) => {
if (err) console.log(err);
});
sftp.end();
});
}).catch((err) => {
console.log(err, 'catch error');
});
Use this to close the ftp connection:
sftp.end();
Download file while in ssh mode?
I found this while trying to answer your question for myself:
https://askubuntu.com/a/13586/137980
Just install zssh and use Ctrl-@ to go into file transfer mode.
Related Topics
Pack Shared Libraries into the Elf
Secure Way to Run Other People Code (Sandbox) on My Server
Sending Udp Packets from the Linux Kernel
How to Get the Source Code for the Linux Utility Tail
Pthread Mutex Lock Unlock by Different Threads
Prevent Linux Thread from Being Interrupted by Scheduler
Self Modifying Code Always Segmentation Faults on Linux
How to Pass a Wildcard Parameter to a Bash File
Extract Lines Between Two Patterns from a File
Using "$Random" to Generate a Random String in Bash
How Does Bash Deal with Nested Quotes
How to Trim White Space from a Variable in Awk
Randomly Shuffling Lines in Linux/Bash
Replacing Control Character in Sed