source在本机:widows环境
ftp linux机器的内容。
如下代码:package org.luyang.io;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;import org.SystemConfig;public class Ftp {
public static void run() {
String ftpUser = "was";
String ftpPass = "was";
String ftpServer = "wsd-party";
String ftpDir = "/home/was/";
String fileName = "test.txt";
StringBuffer sb = new StringBuffer("ftp://");
sb.append(ftpUser);
if (ftpPass == null || ftpPass.trim().length() > 0) {
sb.append(":").append(ftpPass);
}
sb.append("@").append(ftpServer).append(ftpDir);
sb.append(fileName).append(";type=i");
try {
URL url = new URL(sb.toString());
// java.io.OutputStream out = url.openConnection().getOutputStream();
InputStream in = url.openConnection().getInputStream();
OutputStream out = new FileOutputStream("C:\\SS.log");
byte[] chars = new byte[1024];
while (in.read(chars) > 0) {
out.write(chars);
}
out.flush();
out.close();
} catch (Exception e1) {
e1.printStackTrace();
}
} public static void main(String[] args) {
run();
}
}当执行到:
InputStream in = url.openConnection().getInputStream();
除了以下异常:
java.io.FileNotFoundException: home/was/test.txt
但是事实上,我通过直接在ie地址栏输入
ftp://was:was@wsd-party/home/was/test.txt;type=i
是可以访问到test.txt的内容的啊。这是什么原因造成的啊?
ftp linux机器的内容。
如下代码:package org.luyang.io;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;import org.SystemConfig;public class Ftp {
public static void run() {
String ftpUser = "was";
String ftpPass = "was";
String ftpServer = "wsd-party";
String ftpDir = "/home/was/";
String fileName = "test.txt";
StringBuffer sb = new StringBuffer("ftp://");
sb.append(ftpUser);
if (ftpPass == null || ftpPass.trim().length() > 0) {
sb.append(":").append(ftpPass);
}
sb.append("@").append(ftpServer).append(ftpDir);
sb.append(fileName).append(";type=i");
try {
URL url = new URL(sb.toString());
// java.io.OutputStream out = url.openConnection().getOutputStream();
InputStream in = url.openConnection().getInputStream();
OutputStream out = new FileOutputStream("C:\\SS.log");
byte[] chars = new byte[1024];
while (in.read(chars) > 0) {
out.write(chars);
}
out.flush();
out.close();
} catch (Exception e1) {
e1.printStackTrace();
}
} public static void main(String[] args) {
run();
}
}当执行到:
InputStream in = url.openConnection().getInputStream();
除了以下异常:
java.io.FileNotFoundException: home/was/test.txt
但是事实上,我通过直接在ie地址栏输入
ftp://was:was@wsd-party/home/was/test.txt;type=i
是可以访问到test.txt的内容的啊。这是什么原因造成的啊?
2:ftp是不是匿名访问
3:(";type=i");去掉看看
3 type=i 去掉没有反应2 能不能说清楚点?和匿名有什么关系,我当然不是匿名访问了
不过也看不出你的调用有什么错
我用同样的方法做可以得到。是不是was:was@wsd-party这个:的问题?