微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

服务器Arq主机上的FTP写字符NUL?

如何解决服务器Arq主机上的FTP写字符NUL?

我正在尝试通过FTP写入一个文件,我正在使用的服务器是大型机体系结构,在文件末尾写了字符NUL(或为空)。如果我在其他服务器(例如Windows)上进行测试,则可以正常运行。我尝试编写不同的结束行示例CR,CRLF,LF,结果是相同的,即使在输入中只写了“ hello”,最后添加了nul。该文件的扩展名为.FTP 例: 你好 NULNULNULNULNULNULNULNULNUL

public FTPUploader(String host,String user,String pwd,String contentFile,String fileName) throws Exception{
ftp = new FTPClient();
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftp.connect(host);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
    ftp.disconnect();
    throw new Exception("Exception in connecting to FTP Server");
}
ftp.login(user,pwd);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();

String remotePath = fileName;   

FTPFile[] remoteFiles = ftp.listFiles(remotePath);
System.out.println(contentFile);
/*If exist the file this will an append*/
if (remoteFiles.length > 0)
{
    contentFile = "\n" + contentFile;
    System.out.println(contentFile);
    InputStream targetStream = new ByteArrayInputStream(contentFile.getBytes(StandardCharsets.UTF_8));
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    this.ftp.appendFile(remotePath,targetStream);
    System.out.println("File " + remoteFiles[0].getName() + " exists"); 
}
else/*If no exist the file this will an append*/
{
    System.out.println(contentFile);
    InputStream targetStream = new ByteArrayInputStream(contentFile.getBytes(StandardCharsets.UTF_8));
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    this.ftp.storeFile(remotePath,targetStream);
    System.out.println("File " + remotePath + " does not exists");
}

}

解决方法

如果从大型机到其他服务器,请使用参数LOCSITE TRAILINGBLANKS。这样会将空白保留在记录的末尾。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。