ftp上传问题 用Socket连接ftp服务器,然后嵌入到页面中,是以applet嵌入,抱错说access denies,好象是权限设置的问题,谁有ftp上传的代码共享一个,谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在客户端上传本地文件到服务器是么?那当然要设applet的权限了http://qingyuan18.spaces.live.com/ 这里有我以前写的关于applet权限的设置方法。用java写Ftp上传很简单啊,用sun的FtpClient吧:package com.ideal.rating;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import sun.net.TelnetInputStream;import sun.net.TelnetOutputStream;import sun.net.ftp.FtpClient;public class FTPTools { private FtpClient ftpClient ; private String FtpServer = ""; private String FtpPort = ""; private String FtpUser = ""; private String FtpPwd = ""; /* * 连接FTP服务器 */ public void login() { try { this.ftpClient = new FtpClient(this.FtpServer,Integer.parseInt(this.FtpPort)); //登陆服务端FTP,设定二进制传输方式 this.ftpClient.login(this.FtpUser,this.FtpPwd); //登陆服务端FTP,设定二进制传输方式 this.ftpClient.login(this.FtpUser,this.FtpPwd); } catch (NumberFormatException e) { System.out.println("FTPTools:FTP连接错误!"); e.printStackTrace(); } catch (IOException e) { System.out.println("FTPTools:FTP连接错误!"); e.printStackTrace(); } } public FTPTools(String pm_sFtpServer,String pm_sFtpPort,String pm_sFtpUser,String pm_sFtpPwd) { this.FtpServer = pm_sFtpServer; this.FtpPort = pm_sFtpPort; this.FtpUser = pm_sFtpUser; this.FtpPwd = pm_sFtpPwd; } /* * @完成文件传送操作 * @param pm_oSrcFile */ public void upload(File pm_oSrcFile,String pm_sServerFilePath) { try { //进入上传目录 this.ftpClient.cd(pm_sServerFilePath); //流转换,完成上传操作 TelnetOutputStream out = this.ftpClient.put(pm_oSrcFile.getName()); FileInputStream ins = new FileInputStream(pm_oSrcFile); byte[] tmp = new byte[1024]; int lenth = 0; while((lenth = ins.read(tmp))!=-1) { out.write(tmp,0,lenth); } out.flush(); } catch (IOException e) { System.out.println("FTPTools:FTP上传错误!"); e.printStackTrace(); } } /* * @完成文件下载操作 * @param pm_sServerFilePath 服务器文件路径 * @param pm_sServerFileName 服务器文件名 * @param pm_sDesPath 客户端下载文件存放路径 */ public void download(String pm_sServerFilePath,String pm_sServerFileName,String pm_sDesPath) { try { //登陆服务端FTP,设定二进制传输方式 this.ftpClient.login(this.FtpUser,this.FtpPwd); this.ftpClient.binary(); //进入下载目录 this.ftpClient.cd(pm_sServerFilePath); //流转换,完成下载操作 TelnetInputStream ins = this.ftpClient.get(pm_sServerFileName); FileOutputStream ous = new FileOutputStream(pm_sDesPath+"\\"+pm_sServerFileName); byte[] tmp = new byte[1024]; int lenth = 0; while((lenth = ins.read(tmp))!=-1) { ous.write(tmp,0,lenth); } ous.flush(); } catch (IOException e) { System.out.println("FTPTools:FTP下载错误!"); e.printStackTrace(); } } /** * @param args */ public static void main(String[] args) {// Date a = new Date();// Date b = new Date();// SimpleDateFormat c = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");// System.out.println(c.format(a)); }} 新手提问关于二维数组的问题 请教个问题,安装JDK后,是否不用安装别的就可以运行Swing?我的eclipse无法运行swing,准备重新安装 nutch搜索引擎的部署和配置问题; 怎么把TXT文件的数据读出来? 关于cache的问题 请问Java编程思想第二版好 还是第三版呢 JAVA下面的代码编译不了,说两处错了,到底是那呀? 大哥撇一眼吧! static在类定义中的作用 用Java开发多文档应用程序 【寻人启事】谁能看懂下面的代码?/JAVA 5.0新特性/ jdbc连sqlserver数据库的问题?
http://qingyuan18.spaces.live.com/ 这里有我以前写的关于applet权限的设置方法。
用java写Ftp上传很简单啊,用sun的FtpClient吧:
package com.ideal.rating;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;import sun.net.TelnetInputStream;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;public class FTPTools { private FtpClient ftpClient ;
private String FtpServer = "";
private String FtpPort = "";
private String FtpUser = "";
private String FtpPwd = "";
/*
* 连接FTP服务器
*/
public void login()
{
try
{
this.ftpClient = new FtpClient(this.FtpServer,Integer.parseInt(this.FtpPort));
//登陆服务端FTP,设定二进制传输方式
this.ftpClient.login(this.FtpUser,this.FtpPwd);
//登陆服务端FTP,设定二进制传输方式
this.ftpClient.login(this.FtpUser,this.FtpPwd);
}
catch (NumberFormatException e)
{
System.out.println("FTPTools:FTP连接错误!");
e.printStackTrace();
}
catch (IOException e) {
System.out.println("FTPTools:FTP连接错误!");
e.printStackTrace();
}
}
public FTPTools(String pm_sFtpServer,String pm_sFtpPort,String pm_sFtpUser,String pm_sFtpPwd)
{
this.FtpServer = pm_sFtpServer;
this.FtpPort = pm_sFtpPort;
this.FtpUser = pm_sFtpUser;
this.FtpPwd = pm_sFtpPwd;
}
/*
* @完成文件传送操作
* @param pm_oSrcFile
*/
public void upload(File pm_oSrcFile,String pm_sServerFilePath)
{
try
{
//进入上传目录
this.ftpClient.cd(pm_sServerFilePath);
//流转换,完成上传操作
TelnetOutputStream out = this.ftpClient.put(pm_oSrcFile.getName());
FileInputStream ins = new FileInputStream(pm_oSrcFile);
byte[] tmp = new byte[1024];
int lenth = 0;
while((lenth = ins.read(tmp))!=-1)
{
out.write(tmp,0,lenth);
}
out.flush();
}
catch (IOException e) {
System.out.println("FTPTools:FTP上传错误!");
e.printStackTrace();
}
}
/*
* @完成文件下载操作
* @param pm_sServerFilePath 服务器文件路径
* @param pm_sServerFileName 服务器文件名
* @param pm_sDesPath 客户端下载文件存放路径
*/
public void download(String pm_sServerFilePath,String pm_sServerFileName,String pm_sDesPath)
{
try
{
//登陆服务端FTP,设定二进制传输方式
this.ftpClient.login(this.FtpUser,this.FtpPwd);
this.ftpClient.binary();
//进入下载目录
this.ftpClient.cd(pm_sServerFilePath);
//流转换,完成下载操作
TelnetInputStream ins = this.ftpClient.get(pm_sServerFileName);
FileOutputStream ous = new FileOutputStream(pm_sDesPath+"\\"+pm_sServerFileName);
byte[] tmp = new byte[1024];
int lenth = 0;
while((lenth = ins.read(tmp))!=-1)
{
ous.write(tmp,0,lenth);
}
ous.flush();
}
catch (IOException e) {
System.out.println("FTPTools:FTP下载错误!");
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
// Date a = new Date();
// Date b = new Date();
// SimpleDateFormat c = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
// System.out.println(c.format(a));
}}