繁体   English   中英

将特定文件上传到Java中的文件夹(FTP)

[英]Uploading specific file to a folder (FTP) in java

美好的一天,

我只需要您的程序帮助。.基本上,我的程序打算从本地PC传输文件或复制文件,然后将其传输到远程站点(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(指定的路径无效)

但是目标文件夹是Test这是特定的文件夹/Test/file我希望您可以就此提供帮助。 先感谢您!

EDITED

我尝试使用@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)循环? 更改工作目录后,仅使用不带完整路径的文件名进行上传。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM