Link to home
Start Free TrialLog in
Avatar of sladej
sladejFlag for United States of America

asked on

sun.net.ftp get file from mainframe

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);
SOLUTION
Avatar of Tommy Braas
Tommy Braas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When you do a ftp.cd(), you're merely changing the location from where listings of contents will be provided from.
Avatar of sladej

ASKER

The pdfName is B5342SGU.G5342.PDF00903.C040322.DATA
Why no pdf extension? If that's in the root directory, try

final String pdfName = "/B5342SGU.G5342.PDF00903.C040322.DATA";
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):
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 "/"
Avatar of sladej

ASKER

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>
>>Working directory is "T534201.".

In that case it should be



final String pdfName = "/T534201/B5342SGU.G5342.PDF00903.C040322.DATA";
But just to be sure, instead of

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

can you do

>pwd

and tell us the ouput
That's just

pwd

btw
Avatar of sladej

ASKER

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

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
Avatar of sladej

ASKER

Alright,  I'll go give that a try and post the result in a bit.

thanks,
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.
>>Note the period at the end of the initial directory name

Oh yes - that's pretty odd
Avatar of sladej

ASKER

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
My only other suggestion would be to remove the initial "/":   "T534201./B5342SGU.G5342.PDF00903.C040322.DATA"
And this may be my last one too: ;-)


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

Avatar of sladej

ASKER

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.

Avatar of sladej

ASKER

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.
Avatar of sladej

ASKER

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.
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
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.
>> 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?
Avatar of sladej

ASKER

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.
>>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)
nor i... :-)
8-)