Apache commons net FTPClient storeFile()创建以用户名为前缀的文件



新年快乐!:(

因此,我第一次使用Apache Commons FTPClient将文件FTP到Mainframes FTP服务器。我有下面的代码来设置所需的配置,并最终使用storeFile((FTP文件,除了下面的一个小问题外,它似乎可以工作。

ftpClient.login(username, password);
System.out.println(ftpClient.getReplyString());
File blankFile = new File("./src/main/resources/BLANK.DAT");
System.out.println("File exists: "+ blankFile.exists());
InputStream inputStream = new FileInputStream(blankFile);
ftpClient.sendSiteCommand("sbdataconn=****.****.*****"); --Hidden from post
System.out.println(ftpClient.getReplyString());
ftpClient.sendCommand(FTPCmd.PWD);
System.out.println(ftpClient.getReplyString());
ftpClient.sendSiteCommand("lrecl=80 blksize=3120 recfm=FB");
System.out.println(ftpClient.getReplyString());
ftpClient.sendSiteCommand("pri=5 sec=15");
System.out.println(ftpClient.getReplyString());
ftpClient.storeFile("Destination.File.Name",inputStream);
System.out.println(ftpClient.getReplyString());

相应的控制台输出日志显示:

Connected to ****ftp.****.com.
220-FTPD1 IBM FTP CS V2R3 at *****, 06:46:21 on 2021-01-05.
220 Connection will close if idle for more than 15 minutes.
230 USERNAME is logged on.  Working directory is "USERNAME.".
File exists: true
200 SITE command was accepted
257 "'USERNAME.'" is working directory.
200 SITE command was accepted
200 SITE command was accepted
250 Transfer completed successfully.

Mainframe团队确认他们看到了该文件,但该文件的名称为'USERNAME.Destination.File.Name',但我们需要将该文件命名为'Destination.File.Name',以启动下一步的处理。我的配置中缺少什么吗?或者这是使用Apache Commons对主机进行FTPing时的预期行为。从这里我该怎么走?感谢您的帮助。谢谢

好吧,FTPClient的storeFile((方法中的文件名似乎必须用单引号(''(括起来,才能使用该名称创建文件。因此,解决方案就是简单地更换

ftpClient.storeFile("Destination.File.Name",inputStream);

带有

ftpClient.storeFile("'Destination.File.Name'",inputStream);

它如预期的那样发挥了作用。

谢谢,祝你2021年过得愉快。

最新更新