我正在尝试使用以下方法中的代码将在我的服务器中创建的一些文件复制到 FTP。但奇怪的是我随机地低于错误,我无法弄清楚发生了什么。
Exception =org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
下面是我将文件复制到 FTP 的代码。
public void copyDumpsToFTP() throws SocketException, IOException
{
FTPClient f= new FTPClient();
f.connect(dumpProperties.getProperty("ftpIPAddress"));
boolean flag =f.login(dumpProperties.getProperty("ftpUser"),dumpProperties.getProperty("ftpPassword"));
System.out.println(" is connected to FTP ::"+flag);
// setting fileType to binary
boolean isFileTypeChanged =f.setFileType(FTP.BINARY_FILE_TYPE);
// System.out.println(" Is file type changed to binary :: "+isFileTypeChanged);
// change working directory of FTP Server
boolean isDirectoryChanged =f.changeWorkingDirectory(dumpProperties.getProperty("ftpDirectory"));
System.out.println(" Is the FTP working directory Changed :: "+isDirectoryChanged);
// to copy engineering dump from source to FTP
InputStream inputFileEngg = new FileInputStream(new File(dumpNameEngineering));
boolean isSavedEngg = f.storeFile(dumpProperties.getProperty("dumpNameOfEnggInFTP"), inputFileEngg);
System.out.println("is Engineering dump File Saved in FTP Server :: "+isSavedEngg);
System.out.println(" Engg Dump sucessfully Created and Saved in FTP...");
// to copy correspondance dump from source to FTP
InputStream inputFileCorr = new FileInputStream(new File(dumpNameCorrespondance));
boolean isSavedCorr = f.storeFile(dumpProperties.getProperty("dumpNameOfCorrInFTP"), inputFileCorr);
System.out.println("is Correspondance File Saved in FTP Server :: "+isSavedCorr);
System.out.println(" Correspondance Dump sucessfully Created and Saved in FTP...");
// to copy tmg dump from source to FTP
InputStream inputFileTmg = new FileInputStream(new File(dumpNameTmg));
boolean isSavedTmg = f.storeFile(dumpProperties.getProperty("dumpNameOfTmgInFTP"), inputFileTmg);
System.out.println("is TMG File Saved in FTP Server :: "+isSavedTmg);
System.out.println(" TMG Dump sucessfully Created and Saved in FTP...");
}
程序正在执行直到SOP语句Is the FTP working directory Changed :: true
后者抛出了上面提到的错误。
您要更改的目录应该存在于同一路径上,并且应该具有适当的写入权限,以便 FTP 可以在其上写入。
here...
boolean isDirectoryChanged =f.changeWorkingDirectory(dumpProperties.getProperty("ftpDirectory"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)