This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

FTP file transfer not working from Application Server(WAS)  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

The Ftp file transfer is not working in WAS application server but when i ran as a stand alone Java application it works fine.

The FTP connection gets established but the file not getting uploaded and not even throwing error. Even the file permission is set to RW.

below is the code

import java.io.File;

import com.jscape.inet.ftp.Ftp;
import com.jscape.inet.ftp.FtpException;


public class FTPUploadFileDemo {
public static void main(String[] args) throws Exception {
Ftp ftpClient = getFtpClient("XXXX", "XXX", "XX", "21");
ftpClient.setDir("devdata/reports");
copyFile(ftpClient, "File path in your local", "devdata/reports");
ftpClient.issueCommand(new StringBuilder().append("put ").append("any file from your local").append(" ")
.append("devdata/web_reports").toString());
}

private static Ftp getFtpClient(final String ftpServerName, final String ftpUserName, final String ftpPassword,
final String ftpPort) throws FtpException {
final Ftp ftp = new Ftp(ftpServerName, ftpUserName, ftpPassword);
System.out.println("Connecting....");
ftp.setPort(Integer.valueOf(ftpPort));
System.out.println("Port value set..");
ftp.setTimeout(5000);
System.out.println("Timeout set..");
ftp.connect();
System.out.println("Connected..");
ftp.setAuto(false);
ftp.setAscii();
ftp.setDebug(true);
return ftp;
}

private static void copyFile(final Ftp ftp, final String localPath, final String remotePath) throws FtpException {
System.out.println("Copy File started");
try {
File newFile = null;
newFile = new File(localPath);
System.out.println("Local file ----- " + newFile.getPath());
System.out.println("Remote  file ----- " + remotePath);
ftp.upload(newFile, "Test_File.txt");
System.out.println("Upload Complete-----" + newFile.getPath());
} catch (Exception e) {
e.printStackTrace();
}
}
}


Output:


[3/27/18 10:10:50:660 EDT] 0000002e GpirsFtpUtilH I   Remote  file ----- devdata/reports
[3/27/18 10:10:50:661 EDT] 0000002e SystemOut     O PASV
[3/27/18 10:10:50:664 EDT] 0000002e SystemOut     O 227 Entering Passive Mode (19,110,198,20,178,31)
[3/27/18 10:10:50:676 EDT] 0000002e SystemOut     O QUIT
[3/27/18 10:10:50:678 EDT] 0000002e SystemOut     O 221 Goodbye.


 
Saloon Keeper
Posts: 4744
117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I notice that the output of your System.out.println is not shown. Maybe start with looking into why that is, so that you get better diagnostics.

Wait - you said the standalone code you posted does work, but not when you're using similar code running on an app server? What code is running there?
 
Bartender
Posts: 19727
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea why this is posted in the JSF forum. But JSF doesn't know/care/interfere with FTP.

It's unclear whether or not the ultimate sources for the filepaths in the example are absolute or relative. If they're relative, they should be made absolute, since there's no such thing as a "current" or "working" directory in a web application. So it would be unpredictable where the files being transferred were expected to be.

Actually, the webapp environment doesn't support stdio, either, so there's no absolutely gurantee where/if System.out.println statements would write. The preferred approach is to use a logger.

Finally, any files read or written by a web application must have access rights for the userid that the web application server runs under. There are no separate userids for web applications.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!