500的异常 Command not allowed in Extended Passive mode 的错误怎么解决啊!

solmon 2008-02-27 09:16:39
500的异常
500 Command not allowed in Extended Passive mode 的错误怎么解决啊!
...全文
316 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
solmon 2008-02-28
  • 打赏
  • 举报
回复
调好了。谢谢大家的教导。不胜感激。
ee4456 2008-02-27
  • 打赏
  • 举报
回复
DBUG一下
solmon 2008-02-27
  • 打赏
  • 举报
回复
import sun.net.ftp.*;
import sun.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.*;

public class FTPFile extends Applet
{
/**
*
*/

private static final long serialVersionUID = 1L;
FtpClient aftp;
DataOutputStream outputs ;
TelnetInputStream ins;
TelnetOutputStream outs;
static TextArea lsArea;
Label LblPrompt;
Button BtnConn;
Button BtnClose;
TextField TxtUID;
TextField TxtPWD;
TextField TxtHost;
int ch;
public String a="没有连接主机";
String hostname="";
public void init ()
{
setBackground(Color.white);
setLayout(new GridBagLayout());
GridBagConstraints GBC = new GridBagConstraints();
LblPrompt = new Label("没有连接主机");
LblPrompt.setAlignment(Label.LEFT);

BtnConn = new Button("连接");
BtnClose = new Button("断开");
BtnClose.enable(false);
TxtUID = new TextField("",15);
TxtPWD = new TextField("",15);
TxtPWD.setEchoCharacter('*');
TxtHost = new TextField("",20);
Label LblUID = new Label("User ID:");
Label LblPWD = new Label("PWD:");
Label LblHost = new Label("Host:");

lsArea = new TextArea(30,80);
lsArea.setEditable(false);

GBC.gridwidth= GridBagConstraints.REMAINDER;
GBC.fill = GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(LblPrompt,GBC);
add(LblPrompt);

GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblHost,GBC);
add(LblHost);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(TxtHost,GBC);
add(TxtHost);

GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblUID,GBC);
add(LblUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtUID,GBC);
add(TxtUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblPWD,GBC);
add(LblPWD);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtPWD,GBC);
add(TxtPWD);

GBC.gridwidth=1;
GBC.weightx=2;
((GridBagLayout)getLayout()).setConstraints(BtnConn,GBC);
add(BtnConn);
GBC.gridwidth=GridBagConstraints.REMAINDER;

((GridBagLayout)getLayout()).setConstraints(BtnClose,GBC);
add(BtnClose);

GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill = GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(lsArea,GBC);
add(lsArea);
}
public boolean connect(String hostname, String uid,String pwd)
{
this.hostname = hostname;
LblPrompt.setText("正在连接,请等待.....");
try{
aftp =new FtpClient(hostname);
aftp.login(uid,pwd);
aftp.binary();
//this.download("c:\\XMLFile.xml","XMLFile.xml");
//DownLoad.download("c:\\XMLFile.xml","XMLFile.xml", aftp);
showFileContents();
}
catch(FtpLoginException e){
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
catch (IOException e){
a="连接主机:"+hostname+"失败!";
LblPrompt.setText(a);
return false;
}
catch(SecurityException e)
{
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
LblPrompt.setText("连接主机:"+hostname+"成功!");
DownLoad.download("c:\\XMLFile.xml","NewC3Test\\XMLFile.xml", aftp);
return true;
}

public void stop()
{
try
{
aftp.closeServer();
}
catch(IOException e)
{
}
}

public void paint(Graphics g)
{
}

public boolean action(Event evt,Object obj)
{

if (evt.target == BtnConn)
{
LblPrompt.setText("正在连接,请等待.....");
if (connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText()))
{
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
}
return true;
}
if (evt.target == BtnClose)
{
stop();
BtnConn.enable(true);
BtnClose.enable(false);
LblPrompt.setText("与主机"+hostname+"连接已断开!");
return true;
}
return super.action(evt,obj);
}
public boolean sendFile(String filepathname)
{
boolean result=true;
if (aftp != null)
{
LblPrompt.setText("正在粘贴文件,请耐心等待....");
String contentperline;
try{
a="粘贴成功!";
String fg =new String("\\");
int index = filepathname.lastIndexOf(fg);
String filename = filepathname.substring(index+1);
File localFile ;
localFile = new File(filepathname) ;
RandomAccessFile sendFile = new RandomAccessFile(filepathname,"r");
//
sendFile.seek(0);
outs = aftp.put(filename);
outputs = new DataOutputStream(outs);
while (sendFile.getFilePointer() < sendFile.length())
{
ch = sendFile.read();
outputs.write(ch);
}
outs.close();
sendFile.close();
}
catch(IOException e){
a = "粘贴失败!";
result = false ;
}
LblPrompt.setText(a);
showFileContents();
}
else{
result = false;
}
return result;
}

public void showFileContents()
{
StringBuffer buf = new StringBuffer();
lsArea.setText("");
try
{
ins= aftp.list();
while ((ch=ins.read())>=0){
buf.append((char)ch);
}
//lsArea.appendText(buf.toString());
Demo demo = new Demo();
demo.f1(aftp);
ins.close();
}
catch(IOException e)
{
}
}

public static void main(String args[])
{
Frame f = new Frame("FTP XML");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
FTPFile ftp = new FTPFile();
ftp:ftp.init();
ftp:ftp.start();
f.add(ftp);
f.pack();
f.setVisible(true);
}
}

这个是我的代码
不知道是哪出的错
solmon 2008-02-27
  • 打赏
  • 举报
回复
调试运行的时候报的异常
yami251139 2008-02-27
  • 打赏
  • 举报
回复
命令在passive 模式下部被允許
你是寫的不對還是run錯了啊 。。。。
solmon 2008-02-27
  • 打赏
  • 举报
回复
就是ftp服务器的时候报出的。我写的是一个用ftp连接服务器下载文件的程序。在运行的时候报的这个异常
chenlixun 2008-02-27
  • 打赏
  • 举报
回复
1:更改服务器的FTP 模式(扩展被动模式)。
2:看sun.net.ftp.*源代码或文档,是否有支持(扩展被动模式)的命令。

62,615

社区成员

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

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