[英]download a file from a Remote Server to my Localhost
I want to copy a video file from a remote server to my localhost, so I have:我想将视频文件从远程服务器复制到我的本地主机,所以我有:
const ftp = require("basic-ftp");
const path = 'C:\inetpub\wwwroot\Server\views\admin\files\session\trimed\oblivin.mp4';
example()
async function example() {
const client = new ftp.Client()
client.ftp.verbose = true
try {
await client.access({
host: "****",
user: "****",
password: "****",
secure: false
});
await client.ensureDir("movies");
console.log(await client.list());
await client.downloadTo(path, "oblivin.mp4");
}
catch (err) {
console.log(err)
}
client.close()
}
But it just create a file with 0 mb of size in local!但它只是在本地创建一个大小为 0 mb 的文件!
How to fix this?如何解决这个问题?
I am using php script to achieve this.... here is the code:我正在使用 php 脚本来实现这个....这是代码:
<?php // define some variables
$local_file = 'myfile.zip'; // local path
$server_file = 'server.zip'; // Server file
// set up basic connection
$conn_id = ftp_connect($ftp_server); // ftp host
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY))
{
echo "Successfully written to $local_file\n";
}
else
{
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>
Please try the below code:请尝试以下代码:
fetch('C:\inetpub\wwwroot\Server\views\admin\files\session\trimed\oblivin.mp4').then(resp => resp.blob()).then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// change the filename as you want to download
a.download = 'todo-1.json';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
alert('your file has downloaded!'); }).catch(() => alert('Error occurred!'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.