问题是这样的,我在类的main方法里面写了一个ftp上传的方法,没问题可以实现,我们现在有个ftp服务器,
但是我写成项目,部署到linux环境下后,就不行了,
用main方法上传能成功,因为文件就在本地,而部署到环境下后,文件在客户端了,
不知道大家能不能明白我说的,
其实很简单,就是web上怎么调用ftp的方法,上传文件。
我的核心方法:
public static boolean uploadFiles(String remoteFile,File localFile,String path) {
boolean flag=false;
OutputStream out=null;
try
{
//Tools.getRootPath()+path为客户端本地的文件路径
File f=new File(Tools.getRootPath()+path);
if(!f.exists()){
f.mkdirs();
}
ftp.cwd(path);
RandomAccessFile raf=new RandomAccessFile(localFile,"r");
out=ftp.appendFileStream(new String(remoteFile.getBytes("utf-8"),"iso-8859-1"));
byte[] bytes = new byte[1024];
int c=0;
//开始上传
while((c = raf.read(bytes))!= -1){
out.write(bytes,0,c);
out.flush();
}
if(c==-1){
flag=true;
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally{
try
{
if(out!=null){
out.close();
}
if(ftp!=null){
ftp.logout();
ftp.disconnect();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
return flag;
}因为部署后,不可能在服务器上有这样的文件啊。ftpwebftp服务器
但是我写成项目,部署到linux环境下后,就不行了,
用main方法上传能成功,因为文件就在本地,而部署到环境下后,文件在客户端了,
不知道大家能不能明白我说的,
其实很简单,就是web上怎么调用ftp的方法,上传文件。
我的核心方法:
public static boolean uploadFiles(String remoteFile,File localFile,String path) {
boolean flag=false;
OutputStream out=null;
try
{
//Tools.getRootPath()+path为客户端本地的文件路径
File f=new File(Tools.getRootPath()+path);
if(!f.exists()){
f.mkdirs();
}
ftp.cwd(path);
RandomAccessFile raf=new RandomAccessFile(localFile,"r");
out=ftp.appendFileStream(new String(remoteFile.getBytes("utf-8"),"iso-8859-1"));
byte[] bytes = new byte[1024];
int c=0;
//开始上传
while((c = raf.read(bytes))!= -1){
out.write(bytes,0,c);
out.flush();
}
if(c==-1){
flag=true;
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally{
try
{
if(out!=null){
out.close();
}
if(ftp!=null){
ftp.logout();
ftp.disconnect();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
return flag;
}因为部署后,不可能在服务器上有这样的文件啊。ftpwebftp服务器
你没搞过的话,是有点看不明白,搞过的人,差不多一看就明白了,那问问大家,你们的ftp上传都用在了什么地方啊,用在客户端的话不现实吧,不然我们在一些网站上传大文件,比如腾讯,百度什么的就不会那么慢了啊
确实,是可以这样做,谢谢指导啊,我想问下,ftp上传主要用在哪啊,好想安全协议不是很好啊!
平时下班回家玩个2把,呵呵,下班晚了就算了,dota挺能考验一个人的,什么大局观,什么手脑协调,还得会算计,重要的团队合作,我一般出门买组眼直接奔劣势路的。
确实,是可以这样做,谢谢指导啊,我想问下,ftp上传主要用在哪啊,好想安全协议不是很好啊!假如,你的项目是由两部分组成的,而这两部分又不在同一个服务器上,而其中的一个项目又需要另一个项目的数据等,就可以ftp了