获取服务器上存放上传文件的路径

nieweiqi 2008-01-30 08:40:57
我要把这里面的文件上传到FTP服务器上去 两个服务器不是在一台机器上 我想通过页页面来获取服务器上存放上传文件的地址 要是web地址 不能是象本地的那种 . 这样行不?

如果不行那是不是要修改FTPUpLoad 类?
...全文
719 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
olivesoup 2008-01-30
  • 打赏
  • 举报
回复
>我想通过页页面来获取服务器上存放上传文件的地址 要是web地址 不能是象本地的那种 . 这样行不?

首先回答你,也许可以,但是肯定没有客户愿意这么干
这不等于将服务器暴露在外了吗?
你还想要web地址,那就是服务器的ip,端口全都要外泄,这么干这台服务器就玩完了

一般做法是上传的路经事先规定好,写在配置文件中,日后也可以改,用户是看不到的
每次上传从配置文件获取
傻根她弟 2008-01-30
  • 打赏
  • 举报
回复
apache有个文件映射 具体我没配置过,似乎可以解决你这个问题,你可以查一下

要么将ftp上的文件取出后,写入到response(outputStream),以response把文件带到浏览器,由浏览器来提示用户是否愿意保存文件到本
nieweiqi 2008-01-30
  • 打赏
  • 举报
回复
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import sun.net.TelnetOutputStream;
import sun.net.TelnetInputStream;
import sun.net.ftp.FtpClient;

/**
* @author lee_scs
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class FtpUpload
{

String remotefilename;

String localfilename;

FtpClient ftpClient;

public void connectServer(String server, String user, String password,String path)
{
//server:服务器名字

//user:用户名

//password:密码

//path:服务器上的路径
try
{
ftpClient = new FtpClient();
ftpClient.openServer(server,21);
ftpClient.login(user, password);
if (path.length() != 0)
ftpClient.cd(path);
ftpClient.binary();
System.out.println("login in OK!!");
}
catch (IOException ex)
{
ex.toString();
}
}

public void closeConnect() {
try
{

ftpClient.closeServer();
System.out.println("Close OK!!");
}
catch (IOException ex)
{
ex.toString();
}
}

public void upload()
{
this.localfilename="D:ftp.txt";
this.remotefilename="ftp1.txt";

try
{
TelnetOutputStream os = ftpClient.put(this.remotefilename);
java.io.File file_in = new java.io.File(this.localfilename);
FileInputStream is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1)
{
os.write(bytes, 0, c);
}
is.close();
os.close();
System.out.println("UpLoad OK!!");
}
catch (IOException ex)
{
System.out.println("UpLoad Not OK!!");
System.out.println(ex);
}
}

public void download(String localfilename,String remotefilename)
{

String filename = localfilename;
String filename1 = remotefilename;

try
{
TelnetInputStream is = ftpClient.get(filename1);
java.io.File file_in = new java.io.File(filename);
FileOutputStream os = new FileOutputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1)
{
os.write(bytes, 0, c);
}
os.close();
is.close();
}
catch (IOException ex)
{
ex.toString();
}
}
}

我用这个去把上传到web服务器上的文件再上传到FTP但是 出现错误! 应该改那呢?
yy80680169 2008-01-30
  • 打赏
  • 举报
回复
能说的再仔细点么

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧