使用 Java、Apache Common Net 将文件传输到大型机
我正在尝试使用 FTP 将文件上传到大型机服务器。我的代码如下
FTPClient client = new FTPClient();
InputStream in = null;
FileInputStream fis = null;
try {
client.connect("10.10.23.23");
client.login("user1", "pass123");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
int reply ;
reply = client.getReplyCode();
System.out.println("Reply Code:"+reply);
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Positive reply");
String filename ="D:\\FILE.txt";
in = new FileInputStream(filename);
client.storeFile("FILE.TXT", in);
client.logout();
fis.close();
} else {
System.out.println("Negative reply");
}
} catch(final Throwable t){
t.printStackTrace();
}
代码在 client.storeFile("FILE.TXT", in);
中被击中 我无法调试。请提出方法/解决方案。
I'm am trying to upload a file into mainframe server using FTP. My code is below
FTPClient client = new FTPClient();
InputStream in = null;
FileInputStream fis = null;
try {
client.connect("10.10.23.23");
client.login("user1", "pass123");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
int reply ;
reply = client.getReplyCode();
System.out.println("Reply Code:"+reply);
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Positive reply");
String filename ="D:\\FILE.txt";
in = new FileInputStream(filename);
client.storeFile("FILE.TXT", in);
client.logout();
fis.close();
} else {
System.out.println("Negative reply");
}
} catch(final Throwable t){
t.printStackTrace();
}
The code gets struck in client.storeFile("FILE.TXT", in);
I am unable to debug. Please suggest ways / solutions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先是卢卡斯所说的 fis 为空,但我还有很多其他问题。什么是FTP客户端?它不是 sun.net.ftp.FtpClient,因为该类没有
store()
方法。其他需要考虑的事情是登录到大型机,在我工作的地方,您不能在没有先登录的情况下从大型机上获取文件。可能还有更多需要考虑的事情,但让我们从这里开始。First there is what Lukas said fis is null, but I have a bunch of other questions. What is FTPClient? It is not sun.net.ftp.FtpClient as that class has no
store()
method. Other things to consider is logging into the mainframe, where I work you can't just grab files off the mainframe without first logging in. There can be more things to consider but lets start there.在上传文件之前,您似乎没有更改到特定目录。有两种方法可以更改大型机上的目录。如果您需要上传到 PDS,您可以在 Windows FTP 客户端中执行如下命令。
如果您需要将文件上传到 USS 子系统,您将执行如下命令。
You don't appear to be changing to a specific directory before uploading the file. There are two ways of changing directories on the Mainframe. If you need to upload to a PDS you would execute a command like the following from with in the windows ftp client.
If you need to upload a file to the USS subsystem you would execute a command like the following.
你检查过user1有ftp的访问权限吗?可以在非常细粒度的级别上授予这些权限,以便您可以列出文件并提交作业,但不能放置文件。
事实上,它在您发送后立即死亡,这似乎是一个不错的选择。我会打电话给您的 RACF/ACF2/无论您拥有什么安全产品人员并询问他们。
Have you checked that user1 has access permissions to ftp? It is possible to grant those on a very granular level so that you can list files and submit jobs, but not put files.
The fact that it dies right after your SEND seems like that might be a good candidate. I would call your RACF / ACF2 / Whatever-security-product person you have and ask them.