Solved

sun.net.ftp get file from mainframe

Posted on 2004-04-06
31
599 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

809 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