Page 1 of 1

Transfer a file to mainframe using FTP

PostPosted: Fri Jul 05, 2013 12:49 pm
by snkdbpc
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

Re: Transfer a file to mainframe using FTP

PostPosted: Fri Jul 05, 2013 1:12 pm
by Stefan
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'");

Re: Transfer a file to mainframe using FTP

PostPosted: Fri Jul 05, 2013 1:28 pm
by snkdbpc
Thank you, it worked :)

Re: Transfer a file to mainframe using FTP

PostPosted: Fri Jul 05, 2013 1:37 pm
by NicC
Why is this posted in the JAVA section of the forum?