• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

FTP file transfer not working from Application Server(WAS)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7095
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 24287
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I once met a man from Nantucket. He had a tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic