There could be requirement when we have to do a file lookup on different server. My previous code will work when we have server mounted over our PI/PO system. From below code snippet you can do a lookup on any FTP server with the help of credentials.
Below is the code:
This code can be used for anonymous login also. If you are doing anonymous login on FTP server then password string must be blank.
If you are liking this blog then do provide your feedback.
Below is the code:
String host = "<hostname>";
int port = 21;
String username = "anonymous";
String password = "pwd123";
String str = "";
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(host, port);
ftpClient.login(username, password);
ftpClient. enterLocalPassiveMode();
String remoteDirPath = "/sap/PO1/PO_Test/Training/ Rahul/Input";
FTPFile[] files = ftpClient.listFiles( remoteDirPath);
if (files != null && files.length > 0) {
for (FTPFile aFile : files) {
str = aFile.getName();
result.addValue(str);
// str = str + currentFileName;
}
}
result.addValue( "Connection Successful");
ftpClient.logout();
ftpClient.disconnect();
} catch (IOException ex) {
System.err.println(ex);
}This code can be used for anonymous login also. If you are doing anonymous login on FTP server then password string must be blank.
If you are liking this blog then do provide your feedback.
No comments:
Post a Comment