正在将特定文件上传到 java 中的文件夹 (FTP)
Uploading specific file to a folder (FTP) in java
美好的一天,
我只需要你帮助我的程序..基本上我的程序是为了传输文件或从本地电脑复制文件并将其传输到远程站点 (FTP)
这是我的代码:
FTPClient destFtpClient = new FTPClient();
destFtpClient.connect(destIPAddressCom, intPort);
destFtpClient.login(destFtpID, destFtpPwd);
destFtpClient.enterLocalPassiveMode();
destFtpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
String newRoot = recipeRoot.toString();
File[] transFiles = new File(newRoot).listFiles();
for(File file : transFiles) {
for(int i = 0; i < transFiles.length; i++){
File destFile = new File(destTest); //destination path
//File newDestFile = new File(destFile +File.separator+file.getName()); // destination path with the file
FileInputStream fisFile = new FileInputStream(destFile);
destFtpClient.storeFile(file.getName(), fisFile);
fisFile.close();
}
}
我有一个错误:
java.io.FileNotFoundException: \Test (The specified path is invalid)
但目标文件夹是 Test
这是特定文件夹 /Test/file
我希望你能在这方面提供帮助。先感谢您!
已编辑
我尝试使用@Whome 所说的,并且在第一个 运行 它工作然后在尝试重新 运行 之后它突然不工作并得到与上面相同的错误。
destFtpClient.changeWorkingDirectory("//Test");
destFtpClient.makeDirectory("//Test");
File destFile = new File(destTest);
FileInputStream fisFile = new FileInputStream(p1dest);
destFtpClient.storeFile(file.getName(), fisFile);
在上传文件之前尝试使用 ftpclient.changeWorkingDirectory("/Test")
,可能前导 makeDirectory("/Test")
。为什么有 foreach 和 for(idx) 循环?更改工作目录后,只需使用没有完整路径的文件名即可上传。
美好的一天,
我只需要你帮助我的程序..基本上我的程序是为了传输文件或从本地电脑复制文件并将其传输到远程站点 (FTP) 这是我的代码:
FTPClient destFtpClient = new FTPClient();
destFtpClient.connect(destIPAddressCom, intPort);
destFtpClient.login(destFtpID, destFtpPwd);
destFtpClient.enterLocalPassiveMode();
destFtpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
String newRoot = recipeRoot.toString();
File[] transFiles = new File(newRoot).listFiles();
for(File file : transFiles) {
for(int i = 0; i < transFiles.length; i++){
File destFile = new File(destTest); //destination path
//File newDestFile = new File(destFile +File.separator+file.getName()); // destination path with the file
FileInputStream fisFile = new FileInputStream(destFile);
destFtpClient.storeFile(file.getName(), fisFile);
fisFile.close();
}
}
我有一个错误:
java.io.FileNotFoundException: \Test (The specified path is invalid)
但目标文件夹是 Test
这是特定文件夹 /Test/file
我希望你能在这方面提供帮助。先感谢您!
已编辑
我尝试使用@Whome 所说的,并且在第一个 运行 它工作然后在尝试重新 运行 之后它突然不工作并得到与上面相同的错误。
destFtpClient.changeWorkingDirectory("//Test");
destFtpClient.makeDirectory("//Test");
File destFile = new File(destTest);
FileInputStream fisFile = new FileInputStream(p1dest);
destFtpClient.storeFile(file.getName(), fisFile);
在上传文件之前尝试使用 ftpclient.changeWorkingDirectory("/Test")
,可能前导 makeDirectory("/Test")
。为什么有 foreach 和 for(idx) 循环?更改工作目录后,只需使用没有完整路径的文件名即可上传。