Solved

sun.net.ftp get file from mainframe

Posted on 2004-04-06
31
606 Views
Last Modified: 2012-08-14
I am trying to get a file from a mainframe.  I continue to get a filenotfound exception.  When I type the command into a command prompt, I get the file every time.  I was wondering if anyone knows if this api can be used with a java application to get a file from a mainframe?  Here is a small snippet of what I am doing.  Any suggestions or help is greatly needed.  thanks,

//Get FTP properties
String ftpHost      = getStringProperty(CONFIG_KEY_FTP_HOST);
String ftpId        = getStringProperty(CONFIG_KEY_FTP_ID);
String ftpPassword  = getStringProperty(CONFIG_KEY_FTP_PASSWORD);

//Make FTP connection
FtpClient ftp = new FtpClient();

try
{
  ftp.openServer(ftpHost);
  ftpServerOpened = true;
  ftp.login(ftpId, ftpPassword);
}
catch (Throwable t)
{
  m_logger.error("Unable open FTP session on " + ftpHost + " for user " + ftpId,t);
  RenewalException renewalException = new RenewalException("Unable open FTP session on "  +       ftpHost + " for user " + ftpId,t);
  renewalException.setRootCause(t);
  renewalException.setAlarmName("FTP ERROR");
  renewalException.setAlarmTime(new Date());
  throw renewalException;
}      
            
//FTP the file to Eart
boolean successfulFileTransfer = false;
             
//Copy the eArt file we ceated above to the FTP destination.
TelnetInputStream tis     = null;      // Does special treatment of line-endings
            
try
{      
ftp.binary();                                                                              
//ftp.cd(ftpDirectory);
 tis = ftp.get(pdfName);
0
Comment
Question by:sladej
  • 13
  • 10
  • 8
31 Comments
 
LVL 14

Assisted Solution

by:Tommy Braas
Tommy Braas earned 125 total points
ID: 10767312
I believe that you need to specify to full remote path to the file you want to get every time. There is no concept of current directory in ftp.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 10767317
What are you putting in for 'pdfName'?
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10767335
When you do a ftp.cd(), you're merely changing the location from where listings of contents will be provided from.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sladej
ID: 10767341
The pdfName is B5342SGU.G5342.PDF00903.C040322.DATA
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10767372
Why no pdf extension? If that's in the root directory, try

final String pdfName = "/B5342SGU.G5342.PDF00903.C040322.DATA";
0
 

Author Comment

by:sladej
ID: 10767384
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10767414
Please print out here what the listing is from a 'real' ftp client of that file (of course you'll have to have read rights on it too):
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10767483
Is "." really the file separator? Have your tried using "/"?

As in:
ftp.get("/B5342SGU/G5342/PDF00903/C040322/DATA");

The ftp standards document specifies the file separator as being "/"
0
 

Author Comment

by:sladej
ID: 10767501
I don't know if this is what you are talking about but this is what I get when ftping from the command prompt:

User (uhc1ip.uhc.com:(none)): t534201
331 Send password please.
Password:
230 T534201 is logged on.  Working directory is "T534201.".
ftp> get 'B5342SGU.G5342.PDF00903.C040322.DATA'
200 Port request OK.
125 Sending data set B5342SGU.G5342.PDF00903.C040322.DATA
250 Transfer completed successfully.
ftp: 97867 bytes received in 0.36Seconds 271.10Kbytes/sec.
ftp>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10767534
>>Working directory is "T534201.".

In that case it should be



final String pdfName = "/T534201/B5342SGU.G5342.PDF00903.C040322.DATA";
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10767562
But just to be sure, instead of

>>get 'B5342SGU.G5342.PDF00903.C040322.DATA'

can you do

>pwd

and tell us the ouput
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10767569
That's just

pwd

btw
0
 

Author Comment

by:sladej
ID: 10767585
Password:
230 T534201 is logged on.  Working directory is "T534201.".
ftp> pwd
257 "'T534201.'" is working directory.
ftp>

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10767630
OK then it should be

final String pdfName = "/T534201/B5342SGU.G5342.PDF00903.C040322.DATA

If that still produces the same error, can you post the result of

ls -l B5342SGU.G5342.PDF00903.C040322.DATA
0
 

Author Comment

by:sladej
ID: 10767674
Alright,  I'll go give that a try and post the result in a bit.

thanks,
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10767819
Hmm, based on the output from the ftp client it is more likely that the following will work:
final String pdfName = "/T534201./B5342SGU.G5342.PDF00903.C040322.DATA";

Note the period at the end of the initial directory name.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10767905
>>Note the period at the end of the initial directory name

Oh yes - that's pretty odd
0
 

Author Comment

by:sladej
ID: 10768025
I tried it both ways: "/T534201./B5342SGU.G5342.PDF00903.C040322.DATA and /T534201/B5342SGU.G5342.PDF00903.C040322.DATA

both ways gave me the following:

sun.net.ftp.FtpProtocolException: RETR B5342SGU.G5342.PDF00903.C040322.DATA
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10768063
My only other suggestion would be to remove the initial "/":   "T534201./B5342SGU.G5342.PDF00903.C040322.DATA"
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10768111
And this may be my last one too: ;-)


final String pdfName = "~/B5342SGU.G5342.PDF00903.C040322.DATA

0
 

Author Comment

by:sladej
ID: 10768212
I tried T534201./B5342SGU.G5342.PDF00903.C040322.DATA and got the ftpprotocolexception

with "~/B5342SGU.G5342.PDF00903.C040322.DATA, I got the original error:

RETR B5342SGU.G5342.PDF00903.C040322.DATA: 550 Data set T534201.B5342SGU.G5342.PDF00903.C040322.DATA not found

I wonder if this api will work at all with the mainframe.  It doesn't seem to understand the structure in which files are store.

0
 

Author Comment

by:sladej
ID: 10768231
I tried this from the command prompt:

 ls -l B5342SGU.G5342.PDF00903.C040322.DATA

and got

ftp> ls -l B5342SGU.G5342.PDF00903.C040322.DATA
200 Port request OK.
550 No data sets found.
0
 

Author Comment

by:sladej
ID: 10768254
I did a ls and got:

ftp> ls 'B5342SGU.G5342.PDF00903.C040322.DATA'
200 Port request OK.
125 List started OK
'B5342SGU.G5342.PDF00903.C040322.DATA'
250 List completed successfully.
ftp: 40 bytes received in 0.00Seconds 40000.00Kbytes/sec.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10768256
It certainly looks pretty odd to me, but you'd think if you can connect to it with FTP there shouldn't be any protocol problems
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10768306
Yes - to be fair to the server,

ls -l

is beyond the protocol but usually works on Unix servers. Should have guessed, but i wanted to see the *nix file permissions originally. Anyway, i think the perms issue is academic.
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10768481
>> 550 No data sets found.
The above leads me to believe that this 'ftp' implementation is VERY custom. Can you verify the ftp server make and version?
0
 

Author Comment

by:sladej
ID: 10768564
I found the answer of why it is not working.

I needed to add a ftp.cd("//"); after I changed the type to binary.  I am still not sure why but now it works.  Thanks you both for your help.  Do either of you have any problem with me splitting the points between you?  

thanks again.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10768582
>>Do either of you have any problem with me splitting the points between you?  

Not i ;-)

>>I needed to add a ftp.cd("//");

Shouldn't be necessary (as indeed the second forward slash isn't)
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10768722
nor i... :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10768829
8-)
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10768936
=-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 49
Unhandled exception type Exception 18 52
jsp insert to database example 2 62
Website checklist for browser compatibility? 2 38
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question