Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Commons Net FTP客户端赢得';我不提供文件清单_Java_Ftp_Apache Commons Net - Fatal编程技术网

Java Commons Net FTP客户端赢得';我不提供文件清单

Java Commons Net FTP客户端赢得';我不提供文件清单,java,ftp,apache-commons-net,Java,Ftp,Apache Commons Net,我有一个小的ftp java代码,我正试图使用它访问vmware目录下ubuntu机器中的文件。但我一直在犯这样的错误: Current directory is /home/username/Documents Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException at org.apache.commons.ne

我有一个小的ftp java代码,我正试图使用它访问vmware目录下ubuntu机器中的文件。但我一直在犯这样的错误:

    Current directory is /home/username/Documents
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/oro/text/regex/MalformedPatternException
    at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createUnixFTPEntryParser(DefaultFTPFileEntryParserFactory.java:169)
    at org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory.createFileEntryParser(DefaultFTPFileEntryParserFactory.java:94)
    at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2358)
    at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2141)
    at edp_ftp_client.FtpClientMain.main(FtpClientMain.java:54)
Caused by: java.lang.ClassNotFoundException: org.apache.oro.text.regex.MalformedPatternException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more
代码:

公共类FtpClientMain{
公共静态void main(字符串[]args){
String server=“hostname.example.com”;
int端口=21;
字符串user=“username”;
字符串pass=“password”;
String directory=“/home/username/Documents/”;
String dwn_directory=“C:/Users/username/Desktop/files/”;
字符串f_name=“image”;
字符串文件名;
字符串扩展=“.jpg”;
字符串全名、dwn全名;
int rc=0;
int dir_found=0,file_found=0;
int exit=0;
FTPClient FTPClient=新的FTPClient();
试一试{
ftpClient.connect(服务器、端口);
ftpClient.login(用户,通过);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY文件类型);
对于(int i=1;i 0){
//循环通过文件
用于(FTPFile文件:ftpFiles){
如果(!file.isFile()){
继续;
}
System.out.println(“找到文件”);
System.out.println(“文件是”+File.getName());
//获取输出流
输出流输出;
output=newfileoutputstream(“FtpFiles”+“/”+file.getName());
//从远程系统获取文件
ftpClient.retrieveFile(file.getName(),输出);
//关闭输出流
output.close();
//删除该文件
//ftp.deleteFile(file.getName());
}
}
/*文件下载\u文件=新文件(dwn\u全名);
OutputStream OutputStream=新的BufferedOutputStream(新文件OutputStream(下载_文件));
布尔成功=ftpClient.retrieveFile(全名,outputStream);
outputStream.close();
如果(成功){
System.out.println(“文件#1已成功下载”);
}*/
}
}捕获(IOEX异常){
System.out.println(“错误:+ex.getMessage());
例如printStackTrace();
}最后{
试一试{
如果(ftpClient.isConnected()){
ftpClient.logout();
ftpClient.disconnect();
}
}捕获(IOEX异常){
例如printStackTrace();
}
}
}
}
我可以下载一个文件,但无法列出目录中的所有文件。
我正在使用windows 8.1 home edition,运行一台带有ubuntu操作系统的vmware虚拟机。

堆栈跟踪显示,您缺少对古老且完全过时的雅加达ORO库的依赖


Commons Net 1.4(您提到您正在使用的)也很古老,这就是它依赖于ORO的原因。目前的版本是3.3,这是你应该使用的新东西。commons net网站()上有大量最新的示例(包括FTP)

堆栈跟踪显示您缺少对古老且完全过时的雅加达奥罗图书馆的依赖


Commons Net 1.4(您提到您正在使用的)也很古老,这就是它依赖于ORO的原因。目前的版本是3.3,这是你应该使用的新东西。commons net网站()上有大量最新的示例(包括FTP)

堆栈跟踪显示您缺少对古老且完全过时的雅加达奥罗图书馆的依赖


Commons Net 1.4(您提到您正在使用的)也很古老,这就是它依赖于ORO的原因。目前的版本是3.3,这是你应该使用的新东西。commons net网站()上有大量最新的示例(包括FTP)

堆栈跟踪显示您缺少对古老且完全过时的雅加达奥罗图书馆的依赖


Commons Net 1.4(您提到您正在使用的)也很古老,这就是它依赖于ORO的原因。目前的版本是3.3,这是你应该使用的新东西。commons net网站()上有很多最新的示例(包括FTP)(

您使用的是哪些版本的apache commons net JAR?您好,我使用的是1.4版,我不认为这有什么区别,因为我在网上看到的示例也使用了相同的版本。我知道代码中有错误,或者防火墙之类的东西,但是我找不到,你使用的是哪个版本的apache commons net JAR?嗨,我使用的是1.4版,我不认为这有什么区别,因为我在网上看到的示例也使用了相同的版本。我知道代码中有错误,或者防火墙之类的东西,但是我找不到,你使用的是哪个版本的apache commons net JAR?嗨,我使用的是1.4版,我不认为这有什么区别,因为我在网上看到的示例也使用了相同的版本。我知道代码中有错误,或者防火墙之类的东西,但是我找不到,你使用的是哪个版本的apache commons net JAR?嗨,我使用的是1.4版,我不认为这有什么区别,因为我在网上看到的示例也使用了相同的版本。我知道代码中有错误或者防火墙之类的东西,但我找不到
public class FtpClientMain {

    public static void main(String[] args) {
        String server = "hostname.example.com";
        int port = 21;
        String user = "username";
        String pass = "password";
        String directory = "/home/username/Documents/";
        String dwn_directory = "C:/Users/username/Desktop/files/";
        String f_name = "image";
        String filename;
        String extention = ".jpg";
        String full_name, dwn_full_name;
        int rc = 0;
        int dir_found = 0, file_found = 0;
        int exit = 0;

        FTPClient ftpClient = new FTPClient();
        try {
            ftpClient.connect(server, port);
            ftpClient.login(user, pass);
            ftpClient.enterLocalPassiveMode();
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            for(int i = 1; i<50 ;i++) {
                full_name = directory + f_name + i + extention;
                dwn_full_name = dwn_directory + f_name + i + extention;
                filename = f_name + i + extention;
                ftpClient.changeWorkingDirectory(directory);
                rc = ftpClient.getReplyCode();
                if(rc == 550) {
                    System.out.println("Directory not found");
                    break;
                }
                System.out.println("Current directory is " + ftpClient.printWorkingDirectory());

                //get list of filenames
                FTPFile[] ftpFiles = ftpClient.listFiles(ftpClient.printWorkingDirectory());

                if (ftpFiles != null && ftpFiles.length > 0) {
                    //loop thru files
                    for (FTPFile file : ftpFiles) {
                        if (!file.isFile()) {
                            continue;
                        }
                        System.out.println("Found a file");
                        System.out.println("File is " + file.getName());
                        //get output stream
                        OutputStream output;
                        output = new FileOutputStream("FtpFiles" + "/" + file.getName());
                        //get the file from the remote system
                        ftpClient.retrieveFile(file.getName(), output);
                        //close output stream
                        output.close();

                        //delete the file
                        // ftp.deleteFile(file.getName());

                    }
                }
                /*File download_file = new File(dwn_full_name);
                OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(download_file));
                boolean success = ftpClient.retrieveFile(full_name, outputStream);
                outputStream.close();

                if (success) {
                    System.out.println("File #1 has been downloaded successfully.");
                }*/
            }

        } catch (IOException ex) {
            System.out.println("Error: " + ex.getMessage());
            ex.printStackTrace();
        } finally {
            try {
                if (ftpClient.isConnected()) {
                    ftpClient.logout();
                    ftpClient.disconnect();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

}