Java 通过脚本从文件服务器下载文件
例如,我有三台文件服务器,希望为文件下载添加一个“透明层”(执行一个脚本,获取文件并直接发送给用户) 用户只能使用一个链接访问文件,例如:Java 通过脚本从文件服务器下载文件,java,php,web-services,download,cloud,Java,Php,Web Services,Download,Cloud,例如,我有三台文件服务器,希望为文件下载添加一个“透明层”(执行一个脚本,获取文件并直接发送给用户) 用户只能使用一个链接访问文件,例如: www.mysite.com/download/<UUID_WITH_correctFileServer> www.mysite.com/download/ 我现在要问的问题是: 是否可以为用户提供一个性能良好的单一访问url(如上文) 我认为仅使用一个Javaservlet或php脚本不如在每个文件服务器上使用一个脚本->我的推测:文件从
www.mysite.com/download/<UUID_WITH_correctFileServer>
www.mysite.com/download/
我现在要问的问题是:
- 是否可以为用户提供一个性能良好的单一访问url(如上文)
- 我认为仅使用一个Javaservlet或php脚本不如在每个文件服务器上使用一个脚本->我的推测:文件从文件服务器发送到中心脚本,然后再从中心脚本发送到用户。对吗
- 其他云存储提供商是如何解决这个问题的
<?php
if(isset($_GET['fname']) and $_GET['fname']){
// do something with filename to decide from where to donwload
if($_GET['fname']=="DWSM_Domain.png") header("Location: ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png");
if($_GET['fname']=="file1") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1");
if($_GET['fname']=="file2") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><a href="/test.php?fname=DWSM_Domain.png">DWSM_Domain.png</a></p>
<p><a href="/test.php?fname=file1">file1</a></p>
<p><a href="/test.php?fname=file2">file2</a></p>
</body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="/js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><label onclick="get_file('DWSM_Domain.png')">DWSM_Domain.png</label></p>
<p><label onclick="get_file('file1')">file1</label></p>
<p><label onclick="get_file('file2')">file2</label></p>
<script>
function get_file(thisfile) {
if(thisfile){
var content;
var page = "/test2.php?fname=";
var address = page.concat(thisfile);
$.get(address, function (data) {
content = data;
var newWindow = window.open("","_blank");
newWindow.location.href = content;
});
}
}
</script>
</body>
<?php
if(isset($_GET['fname']) and $_GET['fname']){
// do something with filename to decide from where to donwload
if($_GET['fname']=="DWSM_Domain.png") $targetfile ="ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png";
if($_GET['fname']=="file1") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1";
if($_GET['fname']=="file2") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2";
echo $targetfile;
}
?>
无标题文件
如果您确实希望用户打开另一个窗口,则需要两个php文件
test1.php
<?php
if(isset($_GET['fname']) and $_GET['fname']){
// do something with filename to decide from where to donwload
if($_GET['fname']=="DWSM_Domain.png") header("Location: ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png");
if($_GET['fname']=="file1") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1");
if($_GET['fname']=="file2") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><a href="/test.php?fname=DWSM_Domain.png">DWSM_Domain.png</a></p>
<p><a href="/test.php?fname=file1">file1</a></p>
<p><a href="/test.php?fname=file2">file2</a></p>
</body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="/js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><label onclick="get_file('DWSM_Domain.png')">DWSM_Domain.png</label></p>
<p><label onclick="get_file('file1')">file1</label></p>
<p><label onclick="get_file('file2')">file2</label></p>
<script>
function get_file(thisfile) {
if(thisfile){
var content;
var page = "/test2.php?fname=";
var address = page.concat(thisfile);
$.get(address, function (data) {
content = data;
var newWindow = window.open("","_blank");
newWindow.location.href = content;
});
}
}
</script>
</body>
<?php
if(isset($_GET['fname']) and $_GET['fname']){
// do something with filename to decide from where to donwload
if($_GET['fname']=="DWSM_Domain.png") $targetfile ="ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png";
if($_GET['fname']=="file1") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1";
if($_GET['fname']=="file2") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2";
echo $targetfile;
}
?>
无标题文件
DWSM_Domain.png
文件1
文件2
函数get_文件(thisfile){
如果(此文件){
var含量;
var page=“/test2.php?fname=”;
var address=page.concat(此文件);
$.get(地址、函数(数据){
内容=数据;
var newWindow=window.open(“,”_blank”);
newWindow.location.href=内容;
});
}
}
test2.php
<?php
if(isset($_GET['fname']) and $_GET['fname']){
// do something with filename to decide from where to donwload
if($_GET['fname']=="DWSM_Domain.png") header("Location: ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png");
if($_GET['fname']=="file1") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1");
if($_GET['fname']=="file2") header("Location: ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><a href="/test.php?fname=DWSM_Domain.png">DWSM_Domain.png</a></p>
<p><a href="/test.php?fname=file1">file1</a></p>
<p><a href="/test.php?fname=file2">file2</a></p>
</body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="/js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><label onclick="get_file('DWSM_Domain.png')">DWSM_Domain.png</label></p>
<p><label onclick="get_file('file1')">file1</label></p>
<p><label onclick="get_file('file2')">file2</label></p>
<script>
function get_file(thisfile) {
if(thisfile){
var content;
var page = "/test2.php?fname=";
var address = page.concat(thisfile);
$.get(address, function (data) {
content = data;
var newWindow = window.open("","_blank");
newWindow.location.href = content;
});
}
}
</script>
</body>
<?php
if(isset($_GET['fname']) and $_GET['fname']){
// do something with filename to decide from where to donwload
if($_GET['fname']=="DWSM_Domain.png") $targetfile ="ftp://anonymous:test@mailinator.com@ftp.swfwmd.state.fl.us/pub/CFWI_HAT/DWSM_Domain.png";
if($_GET['fname']=="file1") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file1";
if($_GET['fname']=="file2") $targetfile ="ftp://someuser:somepassword@ftp.swfwmd.state.fl.us/somepath/file2";
echo $targetfile;
}
?>
你当然需要驯服它,以获得准确的行为,但我希望这是一个良好的开端。
这取决于您如何编写代码。如果您读取文件并将其从服务器发送给客户端,或者如果您将客户端重定向到文件所在的服务器。您好,我将进行一些安全检查,然后我想将文件发送给用户(我认为重定向是可以的)。是否有示例代码?这是通过设置标题来实现的吗?我认为
标题(“位置:
ftp://username:password@somedomain.com/somefile.ext“;`应该这样做(假设您需要用户名和密码)。我想打字ftp://Great,因此,只需设置此标头即可直接将文件发送给用户(而不是通过脚本位置),对吗?您希望使用java servelt还是pho?服务器不在同一网络中,因此在进行一些安全检查后,应将用户重定向到原始文件