“Import org.apache.oro cannot be resolved” when trying to list files via FTP The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Variable with quotation marks "$()"
Is this wall load bearing? Blueprints and photos attached
Can each chord in a progression create its own key?
Is every episode of "Where are my Pants?" identical?
Match Roman Numerals
how can a perfect fourth interval be considered either consonant or dissonant?
What happens to a Warlock's expended Spell Slots when they gain a Level?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
What force causes entropy to increase?
Circular reasoning in L'Hopital's rule
Mortgage adviser recommends a longer term than necessary combined with overpayments
Keeping a retro style to sci-fi spaceships?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
How do you keep chess fun when your opponent constantly beats you?
How to handle characters who are more educated than the author?
Accepted by European university, rejected by all American ones I applied to? Possible reasons?
Solving overdetermined system by QR decomposition
Can we generate random numbers using irrational numbers like π and e?
Hello, Goodbye, Adios, Aloha
Why not take a picture of a closer black hole?
Does Parliament hold absolute power in the UK?
Could an empire control the whole planet with today's comunication methods?
Using `min_active_rowversion` for global temporary tables
What was the last x86 CPU that did not have the x87 floating-point unit built in?
“Import org.apache.oro cannot be resolved” when trying to list files via FTP
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Java noob trying my hand at basic FTP. Trying to turn an Apache Commons Net FTP tutorial into a functioning program where users enter server, user, pass and can modify/add/view/delete files.
However, whenever I get to the "list files" command I receive an unusual error. The error is:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
Pattern cannot be resolved to a type
MatchResult cannot be resolved to a type
PatternMatcher cannot be resolved to a type
_matcher_ cannot be resolved
Perl5Matcher cannot be resolved to a type
pattern cannot be resolved
Perl5Compiler cannot be resolved to a type
MalformedPatternException cannot be resolved to a type
result cannot be resolved or is not a field
_matcher_ cannot be resolved
pattern cannot be resolved or is not a field
result cannot be resolved or is not a field
_matcher_ cannot be resolved
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
at org.apache.commons.net.ftp.parser.RegexFTPFileEntryParserImpl.<init>(RegexFTPFileEntryParserImpl.java:19)
at org.apache.commons.net.ftp.parser.ConfigurableFTPFileEntryParserImpl.<init>(ConfigurableFTPFileEntryParserImpl.java:57)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:136)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:119)
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:2359)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2142)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2188)
at ftpconnecter.FTPConnecter.run(FTPConnecter.java:74)
at ftpconnecter.Main.main(Main.java:11)
The class itself is below. Entering a blank line for path in makeDir is what triggers the error. However, the error message is saying that it occurs at line 74, which is the else if for the createDir method. There's no Exception listed either, which I haven't seen before in a Java error message.
As an ancillary question, is the way I'm setting up this method, with one big try-catch block, an effective way of structuring this program?
package ftpconnecter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnecter
public void run()
Scanner reader = new Scanner(System.in);
while(true)
System.out.println("Connect to FTP? (Anything other than Yes quits app)");
String input = reader.nextLine();
if (!input.equals("Yes"))
break;
System.out.println("Server address?");
String server = reader.nextLine().trim();
System.out.println("Username");
String user = reader.nextLine();
System.out.println("Password:");
String pass = reader.nextLine();
int port = 21;
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(server, port);
showServerReply(ftpClient);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode))
System.out.println("Connect failed");
continue;
boolean success = ftpClient.login(user, pass);
showServerReply(ftpClient);
if (!success)
System.out.println("Could not login to the server");
continue;
while(true)
System.out.println("Commands: " + "n" +
"1. List Files & Directories (L)" + "n" +
"2. Create New Directory (D)" + "n" +
"3. Create Nested Directory (N)");
String command = reader.nextLine();
if (command.equals("L"))
System.out.println("What is the file path? (Press enter for all)");
String filePath = reader.nextLine();
FTPFile[] files = ftpClient.listFiles(filePath);
printFileDetails(files);
else if (command.equals("D"))
createDir(ftpClient);
else if (command.equals("N"))
System.out.println("What is your directory path?");
String path = reader.nextLine();
makeDir(ftpClient, path);
else
break;
ftpClient.logout();
ftpClient.disconnect();
catch (IOException ex)
System.out.println("Oops! Something went wrong");
ex.printStackTrace();
private static void showServerReply(FTPClient ftpClient)
String[] replies = ftpClient.getReplyStrings();
if (replies != null && replies.length > 0)
for (String aReply : replies)
System.out.println("SERVER: " + aReply);
private void createDir(FTPClient ftpClient) throws IOException
Scanner reader = new Scanner(System.in);
System.out.println("What is the directory to be created?");
String dirToCreate = reader.nextLine();
boolean success = ftpClient.makeDirectory(dirToCreate);
showServerReply(ftpClient);
if (success)
System.out.println("Successfully created directory: " + dirToCreate);
else
System.out.println("Failed to create directory. See server's reply.");
private void makeDir(FTPClient ftpClient, String dirPath) throws IOException
String[] pathElements = dirPath.split("/");
if (pathElements != null && pathElements.length > 0)
for (String singleDir : pathElements)
boolean exists = ftpClient.changeWorkingDirectory(singleDir);
if (!exists)
boolean created = ftpClient.makeDirectory(singleDir);
if (created)
System.out.println("Created directory " + singleDir);
else
System.out.println("Could not create directory " + singleDir);
private void printFileDetails(FTPFile[] files)
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (FTPFile file : files)
String details = file.getName();
if (file.isDirectory())
details = "[" + details + "]";
details += "tt" + file.getSize();
details += "tt" + dateFormater.format(file.getTimestamp().getTime());
System.out.println(details);
java ftp
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
Java noob trying my hand at basic FTP. Trying to turn an Apache Commons Net FTP tutorial into a functioning program where users enter server, user, pass and can modify/add/view/delete files.
However, whenever I get to the "list files" command I receive an unusual error. The error is:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
Pattern cannot be resolved to a type
MatchResult cannot be resolved to a type
PatternMatcher cannot be resolved to a type
_matcher_ cannot be resolved
Perl5Matcher cannot be resolved to a type
pattern cannot be resolved
Perl5Compiler cannot be resolved to a type
MalformedPatternException cannot be resolved to a type
result cannot be resolved or is not a field
_matcher_ cannot be resolved
pattern cannot be resolved or is not a field
result cannot be resolved or is not a field
_matcher_ cannot be resolved
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
at org.apache.commons.net.ftp.parser.RegexFTPFileEntryParserImpl.<init>(RegexFTPFileEntryParserImpl.java:19)
at org.apache.commons.net.ftp.parser.ConfigurableFTPFileEntryParserImpl.<init>(ConfigurableFTPFileEntryParserImpl.java:57)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:136)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:119)
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:2359)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2142)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2188)
at ftpconnecter.FTPConnecter.run(FTPConnecter.java:74)
at ftpconnecter.Main.main(Main.java:11)
The class itself is below. Entering a blank line for path in makeDir is what triggers the error. However, the error message is saying that it occurs at line 74, which is the else if for the createDir method. There's no Exception listed either, which I haven't seen before in a Java error message.
As an ancillary question, is the way I'm setting up this method, with one big try-catch block, an effective way of structuring this program?
package ftpconnecter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnecter
public void run()
Scanner reader = new Scanner(System.in);
while(true)
System.out.println("Connect to FTP? (Anything other than Yes quits app)");
String input = reader.nextLine();
if (!input.equals("Yes"))
break;
System.out.println("Server address?");
String server = reader.nextLine().trim();
System.out.println("Username");
String user = reader.nextLine();
System.out.println("Password:");
String pass = reader.nextLine();
int port = 21;
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(server, port);
showServerReply(ftpClient);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode))
System.out.println("Connect failed");
continue;
boolean success = ftpClient.login(user, pass);
showServerReply(ftpClient);
if (!success)
System.out.println("Could not login to the server");
continue;
while(true)
System.out.println("Commands: " + "n" +
"1. List Files & Directories (L)" + "n" +
"2. Create New Directory (D)" + "n" +
"3. Create Nested Directory (N)");
String command = reader.nextLine();
if (command.equals("L"))
System.out.println("What is the file path? (Press enter for all)");
String filePath = reader.nextLine();
FTPFile[] files = ftpClient.listFiles(filePath);
printFileDetails(files);
else if (command.equals("D"))
createDir(ftpClient);
else if (command.equals("N"))
System.out.println("What is your directory path?");
String path = reader.nextLine();
makeDir(ftpClient, path);
else
break;
ftpClient.logout();
ftpClient.disconnect();
catch (IOException ex)
System.out.println("Oops! Something went wrong");
ex.printStackTrace();
private static void showServerReply(FTPClient ftpClient)
String[] replies = ftpClient.getReplyStrings();
if (replies != null && replies.length > 0)
for (String aReply : replies)
System.out.println("SERVER: " + aReply);
private void createDir(FTPClient ftpClient) throws IOException
Scanner reader = new Scanner(System.in);
System.out.println("What is the directory to be created?");
String dirToCreate = reader.nextLine();
boolean success = ftpClient.makeDirectory(dirToCreate);
showServerReply(ftpClient);
if (success)
System.out.println("Successfully created directory: " + dirToCreate);
else
System.out.println("Failed to create directory. See server's reply.");
private void makeDir(FTPClient ftpClient, String dirPath) throws IOException
String[] pathElements = dirPath.split("/");
if (pathElements != null && pathElements.length > 0)
for (String singleDir : pathElements)
boolean exists = ftpClient.changeWorkingDirectory(singleDir);
if (!exists)
boolean created = ftpClient.makeDirectory(singleDir);
if (created)
System.out.println("Created directory " + singleDir);
else
System.out.println("Could not create directory " + singleDir);
private void printFileDetails(FTPFile[] files)
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (FTPFile file : files)
String details = file.getName();
if (file.isDirectory())
details = "[" + details + "]";
details += "tt" + file.getSize();
details += "tt" + dateFormater.format(file.getTimestamp().getTime());
System.out.println(details);
java ftp
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
Java noob trying my hand at basic FTP. Trying to turn an Apache Commons Net FTP tutorial into a functioning program where users enter server, user, pass and can modify/add/view/delete files.
However, whenever I get to the "list files" command I receive an unusual error. The error is:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
Pattern cannot be resolved to a type
MatchResult cannot be resolved to a type
PatternMatcher cannot be resolved to a type
_matcher_ cannot be resolved
Perl5Matcher cannot be resolved to a type
pattern cannot be resolved
Perl5Compiler cannot be resolved to a type
MalformedPatternException cannot be resolved to a type
result cannot be resolved or is not a field
_matcher_ cannot be resolved
pattern cannot be resolved or is not a field
result cannot be resolved or is not a field
_matcher_ cannot be resolved
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
at org.apache.commons.net.ftp.parser.RegexFTPFileEntryParserImpl.<init>(RegexFTPFileEntryParserImpl.java:19)
at org.apache.commons.net.ftp.parser.ConfigurableFTPFileEntryParserImpl.<init>(ConfigurableFTPFileEntryParserImpl.java:57)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:136)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:119)
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:2359)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2142)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2188)
at ftpconnecter.FTPConnecter.run(FTPConnecter.java:74)
at ftpconnecter.Main.main(Main.java:11)
The class itself is below. Entering a blank line for path in makeDir is what triggers the error. However, the error message is saying that it occurs at line 74, which is the else if for the createDir method. There's no Exception listed either, which I haven't seen before in a Java error message.
As an ancillary question, is the way I'm setting up this method, with one big try-catch block, an effective way of structuring this program?
package ftpconnecter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnecter
public void run()
Scanner reader = new Scanner(System.in);
while(true)
System.out.println("Connect to FTP? (Anything other than Yes quits app)");
String input = reader.nextLine();
if (!input.equals("Yes"))
break;
System.out.println("Server address?");
String server = reader.nextLine().trim();
System.out.println("Username");
String user = reader.nextLine();
System.out.println("Password:");
String pass = reader.nextLine();
int port = 21;
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(server, port);
showServerReply(ftpClient);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode))
System.out.println("Connect failed");
continue;
boolean success = ftpClient.login(user, pass);
showServerReply(ftpClient);
if (!success)
System.out.println("Could not login to the server");
continue;
while(true)
System.out.println("Commands: " + "n" +
"1. List Files & Directories (L)" + "n" +
"2. Create New Directory (D)" + "n" +
"3. Create Nested Directory (N)");
String command = reader.nextLine();
if (command.equals("L"))
System.out.println("What is the file path? (Press enter for all)");
String filePath = reader.nextLine();
FTPFile[] files = ftpClient.listFiles(filePath);
printFileDetails(files);
else if (command.equals("D"))
createDir(ftpClient);
else if (command.equals("N"))
System.out.println("What is your directory path?");
String path = reader.nextLine();
makeDir(ftpClient, path);
else
break;
ftpClient.logout();
ftpClient.disconnect();
catch (IOException ex)
System.out.println("Oops! Something went wrong");
ex.printStackTrace();
private static void showServerReply(FTPClient ftpClient)
String[] replies = ftpClient.getReplyStrings();
if (replies != null && replies.length > 0)
for (String aReply : replies)
System.out.println("SERVER: " + aReply);
private void createDir(FTPClient ftpClient) throws IOException
Scanner reader = new Scanner(System.in);
System.out.println("What is the directory to be created?");
String dirToCreate = reader.nextLine();
boolean success = ftpClient.makeDirectory(dirToCreate);
showServerReply(ftpClient);
if (success)
System.out.println("Successfully created directory: " + dirToCreate);
else
System.out.println("Failed to create directory. See server's reply.");
private void makeDir(FTPClient ftpClient, String dirPath) throws IOException
String[] pathElements = dirPath.split("/");
if (pathElements != null && pathElements.length > 0)
for (String singleDir : pathElements)
boolean exists = ftpClient.changeWorkingDirectory(singleDir);
if (!exists)
boolean created = ftpClient.makeDirectory(singleDir);
if (created)
System.out.println("Created directory " + singleDir);
else
System.out.println("Could not create directory " + singleDir);
private void printFileDetails(FTPFile[] files)
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (FTPFile file : files)
String details = file.getName();
if (file.isDirectory())
details = "[" + details + "]";
details += "tt" + file.getSize();
details += "tt" + dateFormater.format(file.getTimestamp().getTime());
System.out.println(details);
java ftp
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
Java noob trying my hand at basic FTP. Trying to turn an Apache Commons Net FTP tutorial into a functioning program where users enter server, user, pass and can modify/add/view/delete files.
However, whenever I get to the "list files" command I receive an unusual error. The error is:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
The import org.apache.oro cannot be resolved
Pattern cannot be resolved to a type
MatchResult cannot be resolved to a type
PatternMatcher cannot be resolved to a type
_matcher_ cannot be resolved
Perl5Matcher cannot be resolved to a type
pattern cannot be resolved
Perl5Compiler cannot be resolved to a type
MalformedPatternException cannot be resolved to a type
result cannot be resolved or is not a field
_matcher_ cannot be resolved
pattern cannot be resolved or is not a field
result cannot be resolved or is not a field
_matcher_ cannot be resolved
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
result cannot be resolved or is not a field
at org.apache.commons.net.ftp.parser.RegexFTPFileEntryParserImpl.<init>(RegexFTPFileEntryParserImpl.java:19)
at org.apache.commons.net.ftp.parser.ConfigurableFTPFileEntryParserImpl.<init>(ConfigurableFTPFileEntryParserImpl.java:57)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:136)
at org.apache.commons.net.ftp.parser.UnixFTPEntryParser.<init>(UnixFTPEntryParser.java:119)
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:2359)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2142)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2188)
at ftpconnecter.FTPConnecter.run(FTPConnecter.java:74)
at ftpconnecter.Main.main(Main.java:11)
The class itself is below. Entering a blank line for path in makeDir is what triggers the error. However, the error message is saying that it occurs at line 74, which is the else if for the createDir method. There's no Exception listed either, which I haven't seen before in a Java error message.
As an ancillary question, is the way I'm setting up this method, with one big try-catch block, an effective way of structuring this program?
package ftpconnecter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class FTPConnecter
public void run()
Scanner reader = new Scanner(System.in);
while(true)
System.out.println("Connect to FTP? (Anything other than Yes quits app)");
String input = reader.nextLine();
if (!input.equals("Yes"))
break;
System.out.println("Server address?");
String server = reader.nextLine().trim();
System.out.println("Username");
String user = reader.nextLine();
System.out.println("Password:");
String pass = reader.nextLine();
int port = 21;
FTPClient ftpClient = new FTPClient();
try
ftpClient.connect(server, port);
showServerReply(ftpClient);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode))
System.out.println("Connect failed");
continue;
boolean success = ftpClient.login(user, pass);
showServerReply(ftpClient);
if (!success)
System.out.println("Could not login to the server");
continue;
while(true)
System.out.println("Commands: " + "n" +
"1. List Files & Directories (L)" + "n" +
"2. Create New Directory (D)" + "n" +
"3. Create Nested Directory (N)");
String command = reader.nextLine();
if (command.equals("L"))
System.out.println("What is the file path? (Press enter for all)");
String filePath = reader.nextLine();
FTPFile[] files = ftpClient.listFiles(filePath);
printFileDetails(files);
else if (command.equals("D"))
createDir(ftpClient);
else if (command.equals("N"))
System.out.println("What is your directory path?");
String path = reader.nextLine();
makeDir(ftpClient, path);
else
break;
ftpClient.logout();
ftpClient.disconnect();
catch (IOException ex)
System.out.println("Oops! Something went wrong");
ex.printStackTrace();
private static void showServerReply(FTPClient ftpClient)
String[] replies = ftpClient.getReplyStrings();
if (replies != null && replies.length > 0)
for (String aReply : replies)
System.out.println("SERVER: " + aReply);
private void createDir(FTPClient ftpClient) throws IOException
Scanner reader = new Scanner(System.in);
System.out.println("What is the directory to be created?");
String dirToCreate = reader.nextLine();
boolean success = ftpClient.makeDirectory(dirToCreate);
showServerReply(ftpClient);
if (success)
System.out.println("Successfully created directory: " + dirToCreate);
else
System.out.println("Failed to create directory. See server's reply.");
private void makeDir(FTPClient ftpClient, String dirPath) throws IOException
String[] pathElements = dirPath.split("/");
if (pathElements != null && pathElements.length > 0)
for (String singleDir : pathElements)
boolean exists = ftpClient.changeWorkingDirectory(singleDir);
if (!exists)
boolean created = ftpClient.makeDirectory(singleDir);
if (created)
System.out.println("Created directory " + singleDir);
else
System.out.println("Could not create directory " + singleDir);
private void printFileDetails(FTPFile[] files)
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (FTPFile file : files)
String details = file.getName();
if (file.isDirectory())
details = "[" + details + "]";
details += "tt" + file.getSize();
details += "tt" + dateFormater.format(file.getTimestamp().getTime());
System.out.println(details);
java ftp
java ftp
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 mins ago
JeremiahDixonJeremiahDixon
164
164
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
JeremiahDixon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
JeremiahDixon is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217347%2fimport-org-apache-oro-cannot-be-resolved-when-trying-to-list-files-via-ftp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
JeremiahDixon is a new contributor. Be nice, and check out our Code of Conduct.
JeremiahDixon is a new contributor. Be nice, and check out our Code of Conduct.
JeremiahDixon is a new contributor. Be nice, and check out our Code of Conduct.
JeremiahDixon is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217347%2fimport-org-apache-oro-cannot-be-resolved-when-trying-to-list-files-via-ftp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown