如何使用java将文件复制到ftp位置的特定文件夹?

时间:2015-02-02 20:16:53

标签: java ftp

我想将文件复制到ftp服务器中的特定文件夹。

 String server = "www.myserver.com";
        int port = 21;
        String user = "user";
        String pass = "pass";

        FTPClient ftpClient = new FTPClient();
        try {

            ftpClient.connect(server, port);
            ftpClient.login(user, pass);
            ftpClient.enterLocalPassiveMode();

            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            // APPROACH #1: uploads first file using an InputStream
            File firstLocalFile = new File(System.getProperty("user.dir")+"/abc.txt");

            String firstRemoteFile = "abc.txt";
            InputStream inputStream = new FileInputStream(firstLocalFile);

            System.out.println("Start uploading first file");
            boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);
            inputStream.close();
            if (done) {
                System.out.println("The first file is uploaded successfully.");
            }
        }catch(Exception e){
            e.printStackTrace();
        }

这就是我现在所拥有的。如何指定远程目录?

0 个答案:

没有答案