java.io.FileNotFoundException: PORT 192,168,1,79,13,205: 550 Permission denied. at sun.net.ftp.FtpClient.readReply(Unknown Source)
at sun.net.ftp.FtpClient.issueCommand(Unknown Source)
at sun.net.ftp.FtpClient.openDataConnection(Unknown Source)
at sun.net.ftp.FtpClient.put(Unknown Source)
at com.gtime.information.dao.test.FtpTool.upload(FtpTool.java:97)
at com.gtime.information.dao.test.FtpTool.main(FtpTool.java:122)
at sun.net.ftp.FtpClient.issueCommand(Unknown Source)
at sun.net.ftp.FtpClient.openDataConnection(Unknown Source)
at sun.net.ftp.FtpClient.put(Unknown Source)
at com.gtime.information.dao.test.FtpTool.upload(FtpTool.java:97)
at com.gtime.information.dao.test.FtpTool.main(FtpTool.java:122)
解决方案 »
- java jdic
- 关于java中的异常
- 如何设置Icon的图片大小
- mysql的问题
- 有没有办法把一个StringBuffer的内容以下载文件的方式在客户端下载?
- java,常用的开发工具,可视化强
- 怎么创建多级路径?
- 我在学java不知用什么样的工具请大家帮个忙!谢谢!
- 新手请教:哪位帮忙看看这段程序(用Applet画折线图)参数是接收到了并付给了数组,可就是出不了图???
- Zxing生成二维码,改变马眼形状
- 【求助】请问添加到什么容器中的类才必须的同时重写equals方法和hashCode方法? 为什么添加到TreeSet中的不需要重写equals方法 和 hashCode 方法?
- FileInputStream,FileOutputStream在控制台中文显示乱码,如何解决?
忘了好久没有玩JFTP了
ftpClient.binary();
sun.net.TelnetInputStream os = ftpClient.get(file);
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;import nc.itf.doc.DocDelegator;
import nc.vo.doc.doc_007.DirVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTP;public class FtpTool {
private FTPClient ftp; private String romateDir = ""; private String userName = ""; private String password = ""; private String host = ""; private String port = "21"; public FtpTool(String url) throws IOException {
//String url="ftp://user:password@ip:port/ftptest/psd";
int len = url.indexOf("//");
String strTemp = url.substring(len + 2);
len = strTemp.indexOf(":");
userName = strTemp.substring(0, len);
strTemp = strTemp.substring(len + 1); len = strTemp.indexOf("@");
password = strTemp.substring(0, len);
strTemp = strTemp.substring(len + 1);
host = "";
len = strTemp.indexOf(":");
if (len < 0)//没有设置端口
{
port = "21";
len = strTemp.indexOf("/");
if (len > -1) {
host = strTemp.substring(0, len);
strTemp = strTemp.substring(len + 1);
} else {
strTemp = "";
}
} else {
host = strTemp.substring(0, len);
strTemp = strTemp.substring(len + 1);
len = strTemp.indexOf("/");
if (len > -1) {
port = strTemp.substring(0, len);
strTemp = strTemp.substring(len + 1);
} else {
port = "21";
strTemp = "";
}
}
romateDir = strTemp;
ftp = new FTPClient();
ftp.connect(host, FormatStringToInt(port)); } public FtpTool(String host, int port) throws IOException {
ftp = new FTPClient();
ftp.connect(host, port);
} public String login(String username, String password) throws IOException {
this.ftp.login(username, password);
return this.ftp.getReplyString();
} public String login() throws IOException {
this.ftp.login(userName, password);
System.out.println("ftp用户: " + userName);
System.out.println("ftp密码: " + password);
if (!romateDir.equals(""))
System.out.println("cd " + romateDir);
ftp.changeWorkingDirectory(romateDir);
return this.ftp.getReplyString();
} public boolean upload(String pathname, String filename) throws IOException, BusinessException { int reply;
int j;
String m_sfilename = null;
filename = CheckNullString(filename);
if (filename.equals(""))
return false;
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.out.println("FTP server refused connection.");
System.exit(1);
}
FileInputStream is = null;
try {
File file_in;
if (pathname.endsWith(File.separator)) {
file_in = new File(pathname + filename);
} else {
file_in = new File(pathname + File.separator + filename);
}
if (file_in.length() == 0) {
System.out.println("上传文件为空!");
return false;
}
//产生随机数最大到99
j = (int)(Math.random()*100);
m_sfilename = String.valueOf(j) + ".pdf"; // 生成的文件名
is = new FileInputStream(file_in);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.storeFile(m_sfilename, is);
ftp.logout();
} finally {
if (is != null) {
is.close();
}
}
System.out.println("上传文件成功!");
return true;
}
public boolean delete(String filename) throws IOException {
FileInputStream is = null;
boolean retValue = false;
try {
retValue = ftp.deleteFile(filename);
ftp.logout();
} finally {
if (is != null) {
is.close();
}
}
return retValue;
} public void close() {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
} public static int FormatStringToInt(String p_String) {
int intRe = 0;
if (p_String != null) {
if (!p_String.trim().equals("")) {
try {
intRe = Integer.parseInt(p_String);
} catch (Exception ex) { }
}
}
return intRe;
} public static String CheckNullString(String p_String) {
if (p_String == null)
return "";
else
return p_String;
}
public boolean downfile(String pathname, String filename) {
String outputFileName = null;
boolean retValue = false;
try {
FTPFile files[] = ftp.listFiles();
int reply = ftp.getReplyCode(); ////////////////////////////////////////////////
if (!FTPReply.isPositiveCompletion(reply)) {
try {
throw new Exception("Unable to get list of files to dowload.");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/////////////////////////////////////////////////////
if (files.length == 0) {
System.out.println("No files are available for download.");
}else {
for (int i=0; i<files.length; i++) {
System.out.println("Downloading file "+files[i].getName()+"Size:"+files[i].getSize());
outputFileName = pathname + filename + ".pdf";
//return outputFileName;
File f = new File(outputFileName);
//////////////////////////////////////////////////////
retValue = ftp.retrieveFile(outputFileName, new FileOutputStream(f));
if (!retValue) {
try {
throw new Exception ("Downloading of remote file"+files[i].getName()+" failed. ftp.retrieveFile() returned false.");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/////////////////////////////////////////////////////////////
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return retValue;
}
}
用这个例子吧.测试通过的