使用 Java、Apache Common Net 将文件传输到大型机

发布于 2024-10-10 00:38:56 字数 910 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

皇甫轩 2024-10-17 00:38:56

首先是卢卡斯所说的 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.

栀梦 2024-10-17 00:38:56

在上传文件之前,您似乎没有更改到特定目录。有两种方法可以更改大型机上的目录。如果您需要上传到 PDS,您可以在 Windows FTP 客户端中执行如下命令。

cd USERID.DATASET.PREFIX

如果您需要将文件上传到 USS 子系统,您将执行如下命令。

cd '/direone/dirtwo'

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.

cd USERID.DATASET.PREFIX

If you need to upload a file to the USS subsystem you would execute a command like the following.

cd '/direone/dirtwo'
天暗了我发光 2024-10-17 00:38:56

你检查过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.

难以启齿的温柔 2024-10-17 00:38:56
  1. 首先从文件名中删除文件扩展名
  2. ,将修剪后的结果文件名括在单引号内
  3. ,现在将上述字符串作为 storeFile() 方法的第一个参数
  1. first remove the file extension from the file name
  2. enclose the resultant file name after trimming within single quotes
  3. now put the above string as the first parameter of storeFile() method
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文