Transfer a file to mainframe using FTP



Support for Java SE, EE & ME, JVM, JNI, JDBC, EJB, JFC, JPDA, JAAS,JCE, JAXP, XML and Java API.

Transfer a file to mainframe using FTP

Postby snkdbpc » Fri Jul 05, 2013 12:49 pm

I am trying to transfer from the local file system to mainframe via the FTP protocol.I am using the apache.common.net library.The code is as follows,
FTPClient ftp = null;
InputStream in = null;
ftp = new FTPClient();
ftp.connect(hostName);
ftp.login(username, password);
ftp.enterLocalPassiveMode();
ftp.setFileType(FTP.ASCII_FILE_TYPE);
int reply = ftp.getReplyCode();
System.out.println("Received Reply from FTP Connection:" + reply);
if (FTPReply.isPositiveCompletion(reply))
System.out.println("Connected To Server Successfully");
else
System.out.println("Not connected to Server..Check ID,Password,connecivity");
boolean success = ftp.changeWorkingDirectory("'CICS.MAPLIB'");
if (success)
System.out.println("Successfully changed working directory.");
else
System.out.println("Failed to change working directory. See server's reply.");
File f1 = new File(location);
in = new FileInputStream(f1);
boolean done = ftp.storeFile("File", in);
in.close();
if (done)
System.out.println("FILE IS UPLOADED SUCCESSFULY");
else
System.out.println("FILE IS NOT UPLOADED SUCCESSFULLY");
ftp.logout();
ftp.disconnect();

I am taking username,password,hostname and location as parameters to the method.I previously created a PDS named 'USERID.CICS.MAPLIB' in z/OS.Now, the problem I am facing is that the file is not uploaded but however if I am not changing the working directory to 'USERID.CICS.MAPLIB', the file gets uploaded to the location 'USERID.File'.I am seeking to upload the file to a new member in the PDS I created earlier.If anyone has any solution, please help.

Thanks in Advance
snkdbpc
 
Posts: 24
Joined: Mon Oct 22, 2012 5:39 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Transfer a file to mainframe using FTP

Postby Stefan » Fri Jul 05, 2013 1:12 pm

I don't know nothing about the language you're using, but if you want to upload to USER.CICS.MAPLIB, then you should specify this data set fully qualified as in
ftp.changeWorkingDirectory("'USER.CICS.MAPLIB'");
There are 10 types of people in the world: Those who understand binary, and those who don't.

These users thanked the author Stefan for the post:
snkdbpc (Fri Jul 05, 2013 1:29 pm)
User avatar
Stefan
 
Posts: 27
Joined: Tue Aug 21, 2012 3:02 pm
Has thanked: 0 time
Been thanked: 2 times

Re: Transfer a file to mainframe using FTP

Postby snkdbpc » Fri Jul 05, 2013 1:28 pm

Thank you, it worked :)
snkdbpc
 
Posts: 24
Joined: Mon Oct 22, 2012 5:39 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Transfer a file to mainframe using FTP

Postby NicC » Fri Jul 05, 2013 1:37 pm

Why is this posted in the JAVA section of the forum?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times


Return to Mainframe Java

 


  • Related topics
    Replies
    Views
    Last post