ftp是可以,但是肯定不好管理,因为下面用户有很多,这样的话使用系统的每个用户都要装上一个ftp软件,而如果需要隔几天就上报一个视频文件,数据库里又没有记录的话,我该怎么去把用户上传的视频文件准确的找出来呢?况且还要根据一些查询条件来进行查询操作(例如时间..等等..). 请问还有没有其它办法? 有没有用来直接上传的方法呢? (难道就真的只有用ftp的方式吗?:( )
解决方案 »
- Struts2.0 静态访问无效
- 探讨
- ejb 如何进行分布式部署
- 在OA系统中怎么集成office插件,给个入手的方向就可以了
- struts2环境搭建,tomcat报错如下,我的包都引进去了
- [高分求解]关于内存泄漏(Tomcat5.5+jdk1.5)
- 新手问关于tomcat下程序的运行错误的问题(在线等!!)
- 菜鸟问题:请问如何在EJB中返回一个ResultSet到JSP(Servlet)~Help me, 急~~~
- 实体bean怎么连接sql server数据库啊??
- PageHelper查询数据分页后,对数据二次处理后,如何更新分页信息?
- 数据库更新出现错误!
- 请问在我的java程序中怎样连接Access数据库??急!!!
public String uploadVideofile(
UploadForm form, // 上传文件表单
String uploadPath, // 写入路径
HttpServletRequest request)
throws FileNotFoundException, IOException {StringBuffer sb = new StringBuffer();
FormFile file = form.getFile(); // 得到上传文件String path = uploadPath;
new File(path).mkdirs(); // 建立写入文件夹
InputStream is = file.getInputStream();
String writePath = path + "/" + file.getFileName(); // 写入文件路径
BufferedOutputStream bos =
new BufferedOutputStream( new FileOutputStream(writePath));
FileIO.copyFile(is, bos, true); // 写文件....
sb.append("视频资料:").append(file.getFileName()).append("上传成功!");
}
return sb.toString();
}它可以上传任意大的文件,因为 file只是一个路径,用Java I/O 写入到另外一个路径即可
/*
* Copyright 2001-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package examples;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
import org.apache.commons.net.ftp.FTPReply;/***
* This is an example program demonstrating how to use the FTPClient class.
* This program connects to an FTP server and retrieves the specified
* file. If the -s flag is used, it stores the local file at the FTP server.
* Just so you can see what's happening, all reply strings are printed.
* If the -b flag is used, a binary transfer is assumed (default is ASCII).
* <p>
* Usage: ftp [-s] [-b] <hostname> <username> <password> <remote file> <local file>
* <p>
***/
public final class ftp
{ public static final String USAGE =
"Usage: ftp [-s] [-b] <hostname> <username> <password> <remote file> <local file>\n" +
"\nDefault behavior is to download a file and use ASCII transfer mode.\n" +
"\t-s store file on server (upload)\n" +
"\t-b use binary transfer mode\n"; public static final void main(String[] args)
{
int base = 0;
boolean storeFile = false, binaryTransfer = false, error = false;
String server, username, password, remote, local;
FTPClient ftp; for (base = 0; base < args.length; base++)
{
if (args[base].startsWith("-s"))
storeFile = true;
else if (args[base].startsWith("-b"))
binaryTransfer = true;
else
break;
} if ((args.length - base) != 5)
{
System.err.println(USAGE);
System.exit(1);
} server = args[base++];
username = args[base++];
password = args[base++];
remote = args[base++];
local = args[base]; ftp = new FTPClient();
ftp.addProtocolCommandListener(new PrintCommandListener(
new PrintWriter(System.out))); try
{
int reply;
ftp.connect(server);
System.out.println("Connected to " + server + "."); // After connection attempt, you should check the reply code to verify
// success.
reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
}
catch (IOException e)
{
if (ftp.isConnected())
{
try
{
ftp.disconnect();
}
catch (IOException f)
{
// do nothing
}
}
System.err.println("Could not connect to server.");
e.printStackTrace();
System.exit(1);
}__main:
try
{
if (!ftp.login(username, password))
{
ftp.logout();
error = true;
break __main;
} System.out.println("Remote system is " + ftp.getSystemName()); if (binaryTransfer)
ftp.setFileType(FTP.BINARY_FILE_TYPE); // Use passive mode as default because most of us are
// behind firewalls these days.
ftp.enterLocalPassiveMode(); if (storeFile)
{
InputStream input; input = new FileInputStream(local);
ftp.storeFile(remote, input);
}
else
{
OutputStream output; output = new FileOutputStream(local);
ftp.retrieveFile(remote, output);
} ftp.logout();
}
catch (FTPConnectionClosedException e)
{
error = true;
System.err.println("Server closed connection.");
e.printStackTrace();
}
catch (IOException e)
{
error = true;
e.printStackTrace();
}
finally
{
if (ftp.isConnected())
{
try
{
ftp.disconnect();
}
catch (IOException f)
{
// do nothing
}
}
} System.exit(error ? 1 : 0);
} // end main}