0

我有一个 java 片段,它将通过 FTP 将字符串(长文本文档)传输到远程位置。一切似乎都在工作,但是当调用 ftp.storeFile(a,b) 时,我的挂起时间很长。然后返回一个replyCode 425。这很奇怪,因为myData.txt 出现在远程目标中,但它是空白的。一定有什么东西阻塞了输入流?有谁知道问题可能是什么?

Java代码:

public void doFTP(){      
       FTPClient ftp = new FTPClient();
       FTPClientConfig config = new FTPClientConfig();
       ftp.configure(config);
       boolean error = false;
       try {
         int reply;
         String server = "example.com";
         ftp.connect(server);
         ftp.login(username, password);
         reply = ftp.getReplyCode();
         if(!FTPReply.isPositiveCompletion(reply)) {
           ftp.disconnect(); 
         } 
         InputStream is = new ByteArrayInputStream(myString.getBytes()); //String
         ftp.setFileType(ftp.BINARY_FILE_TYPE, ftp.BINARY_FILE_TYPE);
         ftp.setFileTransferMode(ftp.BINARY_FILE_TYPE);
         Boolean test = ftp.storeFile("myData.txt", is);  //FTP store here
         System.out.println(test);
         reply = ftp.getReplyCode();
         System.out.println(reply);
         is.close();
         ftp.logout();
       } catch(IOException e) {
       // ... not important
       } finally {
       // ... not important
       }
 }
4

2 回答 2

0

Found the problem, I need to switch it to:

ftp.enterLocalPassiveMode();

I still don't quite understand why this needs to be done, if anyone could care to explain.

于 2013-08-13T20:29:50.287 回答
0

您显示的代码对我来说看起来很奇怪。InputStream所在的位置 = 此代码应位于try { ..... }代码块内。

于 2013-08-13T19:55:57.203 回答