关于javaftp425的信息

博主:adminadmin 2022-11-25 19:23:11 45

本篇文章给大家谈谈javaftp425,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

如何解决ftp出现425 Can’t open data connection错误

ftp服务器是被动模式还是主动模式。被动模式服务端会随机选择一个端口(1024以上)监听(你也可以指定端口),看看是不是防火墙阻止了端口。主动模式使用一般不方便,现在的个人电脑一般都是内网地址,通过路由接入外网,访问外网的ftp时外网机器是无法访问到你的电脑的(除非路由上加了端口映射)

FTP提示425错误

425 Can't open data connection 列表错误 解决方法

尝试方法一:

这个问题主要是由于使用Passive Mode模式造成的,解决这个问题很简单:

1、在ftp服务软件中设置指定端口地址范围,允许Passive Mode使用,比如60000-60020

2、然后在ftp服务器的系统防火墙上打开这些tcp端口,比如是60000-60020,如果使用windows自带的防火墙,就一条一条的增加,20行有点麻烦,但是可以解决。

如果ftp用户较多,可以扩大端口范围。

尝试方法二:

考虑以下原因:

1、防火墙挡住了

2、没有查看内容的权限

3、网管屏蔽了FTP端口 (检查20端口是否开放,如FTP改过端口了1234,刚检查1233端口是否开放)

尝试方法三:

425 Can't open data connection 和 读取目录列表失败 问题解决

这个问题主要是由于使用Passive Mode模式造成的,解决这个问题很简单:1、在ftp服务软件中设置指定端口地址范围,允许Passive Mode使用,比如60000-60020

2、然后在ftp服务器的系统防火墙上打开这些tcp端口

尝试方法四:

是由于服务端防火墙的设置,客户端不能用pasv模式,用户在使用FTP上传文件时出现无法列表的情况,是由于选择在PASV方式下进行上传而导致的。因此,请用户将上传方式改为PORT。相同的软件,版本不同,设置方法也略有不同,因此需要根据实际情况进行设置(连接之前请确保已经关闭防火墙,例如卡巴斯基、瑞星、天网、windowsxp系统自带的防火墙等)。

用JAVA获取FTP文件列表

public class FtpClientUtil {

FtpClient ftpClient;

private String server;

private int port;

private String userName;

private String userPassword;

public FtpClientUtil(String server,int port,String userName,String userPassword)

{

this.server=server;

this.port=port;

this.userName=userName;

this.userPassword=userPassword;

}

/**

* 链接到服务器

* @return

*/

public boolean open()

{

if(ftpClient!=nullftpClient.serverIsOpen())

return true;

try

{

ftpClient= new FtpClient();

ftpClient.openServer(server,port);

ftpClient.login(userName, userPassword);

ftpClient.binary();

return true;

}

catch(Exception e)

{

e.printStackTrace();

ftpClient=null;

return false;

}

}

public boolean cd(String dir){

boolean f = false;

try {

ftpClient.cd(dir);

} catch (IOException e) {

Logs.error(e.toString());

return f;

}

return true;

}

/**

* 上传文件到FTP服务器

* @param localPathAndFileName 本地文件目录和文件名

* @param ftpFileName 上传后的文件名

* @param ftpDirectory FTP目录如:/path1/pathb2/,如果目录不存在回自动创建目录

* @throws Exception

*/

public boolean upload(String localDirectoryAndFileName,String ftpFileName,String ftpDirectory)throws Exception {

if(!open())

return false;

FileInputStream is=null;

TelnetOutputStream os=null;

try

{

char ch = ' ';

if (ftpDirectory.length() 0)

ch = ftpDirectory.charAt(ftpDirectory.length() - 1);

for (; ch == '/' || ch == '\\'; ch = ftpDirectory.charAt(ftpDirectory.length() - 1))

ftpDirectory = ftpDirectory.substring(0, ftpDirectory.length() - 1);

int slashIndex = ftpDirectory.indexOf(47);

int backslashIndex = ftpDirectory.indexOf(92);

int index = slashIndex;

String dirall = ftpDirectory;

if (backslashIndex != -1 (index == -1 || index backslashIndex))

index = backslashIndex;

String directory = "";

while (index != -1) {

if (index 0) {

String dir = dirall.substring(0, index);

directory = directory + "/" + dir;

ftpClient.sendServer("XMKD " + directory + "\r\n");

ftpClient.readServerResponse();

}

dirall = dirall.substring(index + 1);

slashIndex = dirall.indexOf(47);

backslashIndex = dirall.indexOf(92);

index = slashIndex;

if (backslashIndex != -1 (index == -1 || index backslashIndex))

index = backslashIndex;

}

ftpClient.sendServer("XMKD " + ftpDirectory + "\r\n");

ftpClient.readServerResponse();

os = ftpClient.put(ftpDirectory + "/"

+ ftpFileName);

File file_in = new File(localDirectoryAndFileName);

is = new FileInputStream(file_in);

byte bytes[] = new byte[1024];

int i;

while ((i = is.read(bytes)) != -1)

os.write(bytes, 0, i);

//清理垃圾

return true;

}

catch(Exception e)

{

e.printStackTrace();

return false;

}

finally

{

if (is != null)

is.close();

if (os != null)

os.close();

}

}

/**

* 从FTP服务器上下载文件并返回下载文件长度

* @param ftpDirectoryAndFileName

* @param localDirectoryAndFileName

* @return

* @throws Exception

*/

public long download(String ftpDirectoryAndFileName,String localDirectoryAndFileName)throws Exception

{

long result = 0;

if(!open())

return result;

TelnetInputStream is = null;

FileOutputStream os = null;

try

{

is = ftpClient.get(ftpDirectoryAndFileName);

java.io.File outfile = new java.io.File(localDirectoryAndFileName);

os = new FileOutputStream(outfile);

byte[] bytes = new byte[1024];

int c;

while ((c = is.read(bytes)) != -1)

{

os.write(bytes, 0, c);

result = result + c;

}

}

catch (Exception e)

{

throw e;

}

finally

{

if (is != null)

is.close();

if (os != null)

os.close();

}

return result;

}

/**

* 返回FTP目录下的文件列表

* @param ftpDirectory

* @return

*/

public ListString getFileNameList(String ftpDirectory)

{

ListString list = new ArrayListString();

if(!open())

return list;

try

{

DataInputStream dis = new DataInputStream(ftpClient.nameList(ftpDirectory));

String filename = "";

while((filename=dis.readLine())!=null)

{

list.add(filename);

}

} catch (Exception e)

{

e.printStackTrace();

}

return list;

}

/**

* 删除FTP上的文件

* @param ftpDirAndFileName

*/

public boolean deleteFile(String ftpDirAndFileName)

{

if(!open())

return false;

ftpClient.sendServer("DELE "+ftpDirAndFileName+"\r\n");

return true;

}

/**

* 删除FTP目录

* @param ftpDirectory

*/

public boolean deleteDirectory(String ftpDirectory)

{

if(!open())

return false;

ftpClient.sendServer("XRMD "+ftpDirectory+"\r\n");

return true;

}

/**

* 关闭链接

*/

public void close()

{

try

{

if(ftpClient!=nullftpClient.serverIsOpen())

ftpClient.closeServer();

}catch(Exception e)

{

}

}

}

登陆ftp后输入ls报425错误

你的电脑和ftp服务器之间有防火墙吗,你需要在防火墙上把pasv模式下的端口放行才可以。pasv模式下的数据端口不固定,或者在防火墙上放开所有端口,或者在服务器端限制端口的范围

为什么我的ftp连接不管是采取主动还是被动模式,都出现错误号425

看看是不是::

防火墙挡住了或者 网管屏蔽了FTP端口 或者 没有查看内容的权限

再或者,你试试其它文件看了,是不是你要下载的这个文件被损坏了

请教JAVA FTP上传的一个问题

常见问题,供你参考:

在测试过程中抛出一个异常,具体信息如下:

User at logged in.

sun.net.: STOR 111.txt:425 Can't build data connection: Connection timed out.

at sun.net.(Unknown Source)

at sun.net.(Unknown Source)

at com.tools.FtpTool.upload(FtpTool.java:56)

at com.tools.FtpTool.main(FtpTool.java:94)

抛出此异常的具体表现为:在FTP服务器上已经创建了该文件,但文件大小为0。在网上搜索相关异常描述也很少,经过仔细分析发现,此问题与FTP客户端防火墙有关。然后我关闭防火墙软件,再进行测试,一切OK!

在网上也发现另一个常见异常,我将它重现并做说明。其主要原因是很多FTP服务没有使用默认端口,在代码实现中,连接端口不正确所导致异常出现的。

sun.net.: Welcome message: ??$

at sun.net.(Unknown Source)

at com.tools.FtpTool.init(FtpTool.java:29)

at com.tools.FtpTool.main(FtpTool.java:91)

第三种异常就是由于FTP服务器端的FTP服务没有开启,连接被拒绝所导致的。具体异常如下:

java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(Unknown Source)

at java.net.PlainSocketImpl.connectToAddress(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

javaftp425的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javaftp425的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-25,除非注明,否则均为首码项目网原创文章,转载请注明出处。