How to Download File from Server

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

Download File to server from URL

Since PHP 5.1.0, file_put_contents() supports writing piece-by-piece by passing a stream-handle as the $data parameter:

file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", 'r'));

From the manual:

If data [that is the second argument] is a stream resource, the remaining buffer of that stream will be copied to the specified file. This is similar with using
stream_copy_to_stream().

(Thanks Hakre.)

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

PHP - Download file(s) from the server without revealing the URL - A few GOTCHAS

To get this working in my own code, I needed to wrap my PHP variables in either single or double quotes (and sometimes doubled single quotes) as shown below:

header('Content-Type:'.$ctype.'' ); 
header('Content-Disposition: attachment; filename="'.$fname.'"');
readfile(''.$filepath.'');

When entered this way, I was able to download the files without corruption or issue. Please let me know if you are aware of a better way of doing this.

However, when I used the coded above it also allowed me to NOT use the

            ob_clean();
ob_end_flush();

commands in my code. In fact if I add them now . . . it seems to corrupt my files too. Weird.

Another potential GOTCHA is that if you attempt to download a TXT file, and you have a PHP "echo" statement anywhere in your "download.php" file, the contents of the ECHO statement will be appended to the TXTY file that's downloaded. So just something to be careful of.

This ECHO statement may also be appended to the headers of other documents types as well, but it didn't seem to affect the ability of the file to open in my limited testing. But again, be careful out there! :)

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 can I download files from one server to another directly?

This will download to a directory/file you specify;

wget example.com/web/uploads/table.sql -O /path/to/folder/table.sql

https://www.gnu.org/software/wget/manual/wget.html

or

man wget

Download files from server

Try this one

Server

app.post('/imageDownload', async(req, res) => {
const admzip = require('adm-zip')
var zip = new admzip();
var outputFilePath = Date.now() + "output.zip";
zip.addLocalFile('imagepath')
fs.writeFileSync(outputFilePath, zip.toBuffer());
res.download(outputFilePath,(err)=>{
if(err)
console.log(err)
}
})

Client

axios({
url: `/imageDownload`,
method: 'POST',
responseType: 'blob',
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'filename.zip');
document.body.appendChild(link);
link.click();
});

Django view to download a file from server

In order to download a file, you need to return a FileResponse to the user. However, calling an external function that returns a FileResponse won't work because you're not actually returning the FileResponse to the user, in your case the user only receives the render(request, 'generate_mo.html', {'misses':misses,}) so that won't download the files.

You can't download several files one after the others, so I suggest putting them all in a .zip or .tar file so that you can download them as only one file, and only need to return one FileResponse.

As you also need to render your template, what you can do is redirect to your download_mo view on template loading so that your file is downloaded while your template is rendered.

Now, for your download_mo view, just replace your HttpResponse with a FileResponse :

from django.http import FileResponse
def download_mo(request,file):
path_to_file = os.path.realpath(file)
response = FileResponse(open(path_to_file, 'rb'))
file_name = file[5:]
response['Content-Disposition'] = 'inline; filename=' + file_name
return response


Related Topics



Leave a reply



Submit