如何使用 Java 中的 FTP 在大型机上创建数据集



我正在尝试使用 java 将文本文件通过 FTP 传输到大型机。我能够使用以下代码在 PDS 中创建一个成员。

//Function to FTP the report
public void sendReport() throws IOException
{
FTPSClient ftp = null;
InputStream in = null;
String protocol="TLS";
//Connecting to mainframe server for ftp transfer    
ftp = new FTPSClient(protocol); 
ftp.connect(hostname);
ftp.login(user,password);
ftp.execPBSZ(0);
ftp.execPROT("P");
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 Mainframe");
else
System.out.println("Not connected to Mainframe..Check ID or Password");
//Setting mainframe PDS for reports
boolean success = ftp.changeWorkingDirectory("***Mainframe Directory***");
if (success) 
System.out.println("Successfully changed PDS.");
else 
System.out.println("Failed to change PDS. See Mainframe's reply.");
//Sending Report to mainframe PDS
File f1 = new File(dkReportName);
in = new FileInputStream(f1);
boolean done = ftp.storeFile("DKI"+dkReportName.substring(14,18), in);
in.close();
if (done) 
System.out.println("FILE FTP SUCCESSFUL"); 
else 
System.out.println("FILE FTP NOT SUCCESSFUL");
ftp.logout();
ftp.disconnect();
}

用户、密码和主机名变量正在 appContext.xml 中设置。
但是,我想创建一个 PS 数据集。 谁能提出一种方法。

根据您的问题,这是针对 MVS 文件空间而不是 USS。

使用 FTP 创建数据集时,您需要向主机提供有关文件大小、属性等的一些信息。

IBM 网站上的此页面概述了您可以执行的命令列表,以设置传输。 基本顺序如下所示:


site cylsite pri=5site sec=5

site recfm=fb

您可以在一行上组合多个命令:


site lrecl=80 blksize=3120

在传输之前执行这些命令,文件应具有所需的特征。

根据您的编码示例,下面是一个应该可以工作的示例:

ftp.sendCommand("site",
"cyl pri=5 sec=5 recfm=fb filetype=seq lrecl=80 blksize=3120");

最新更新