使用sun.net.ftp.FtpClient类上传和下载时,只能下载,不能上传。主要代码如下:
FtpClient ftp = new FtpClient();
try {
ftp.openServer("192.168.50.69");
ftp.login("admin", "123");
System.out.println(ftp.welcomeMsg);
ftp.binary(); File file = new File(args[0]);
FileInputStream fis = new FileInputStream(file);
TelnetOutputStream tos = ftp.put(args[1]);
byte[] b = new byte[10240];
int c;
while ((c = fis.read(b)) != -1) {
tos.write(b, 0, c);
}
tos.flush();
tos.close();
fis.close();
System.out.println("上传成功");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.out.println("上传失败");
} }
报错信息:
上传失败
sun.net.ftp.FtpProtocolException: 501 Permission Denied at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:385)
at sun.net.ftp.FtpClient.put(FtpClient.java:594)
at cn.com.ust.Demo.main(Demo.java:28)
FTPFtpClient,上传下载
FtpClient ftp = new FtpClient();
try {
ftp.openServer("192.168.50.69");
ftp.login("admin", "123");
System.out.println(ftp.welcomeMsg);
ftp.binary(); File file = new File(args[0]);
FileInputStream fis = new FileInputStream(file);
TelnetOutputStream tos = ftp.put(args[1]);
byte[] b = new byte[10240];
int c;
while ((c = fis.read(b)) != -1) {
tos.write(b, 0, c);
}
tos.flush();
tos.close();
fis.close();
System.out.println("上传成功");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.out.println("上传失败");
} }
报错信息:
上传失败
sun.net.ftp.FtpProtocolException: 501 Permission Denied at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:385)
at sun.net.ftp.FtpClient.put(FtpClient.java:594)
at cn.com.ust.Demo.main(Demo.java:28)
FTPFtpClient,上传下载
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货