0

I use wxFTP to make simple client and I'm stucked on how to Upload recursively my folder or do download (which would should be same as delete) from FTP server. I know how to upload single file, make FTP folder and delete file. I will appreciate an article (not necessarily in C/C++) that teaches the concept or if someone can help me here.

Code example will be appreciated but take that as secondary. Sorry if it already asked and answered, I searched and didn't get anything that answered my question.

4

1 回答 1

0

我将回答这个 问题的代码翻译成 C++,就是这样。由于 So 不会接受答案并将其添加到评论中,因此我添加了我翻译成 C++ 的 Java 代码。我当前的代码太长(因为它涉及的功能很少,所以我猜不适合!

    public void saveFilesToServer(String remoteDest, File localSrc) throws IOException {
    FTPClient ftp = new FTPClient();
    ftp.connect("ftp.foobar.com");
    if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
        ftp.disconnect();
        log.fatal("FTP not disconnected");
    }

    ftp.login("foo", "qwerty");
    log.info("Connected to server .");
    log.info(ftp.getReplyString());

    ftp.changeWorkingDirectory(remoteDest);
    ftp.setFileType(FTPClient.BINARY_FILE_TYPE);

    try {
        upload(localSrc, ftp);
    }
    finally {
        ftp.disconnect();
        log.info("FTP disconnected");           
    }
}

public void upload(File src, FTPClient ftp) throws IOException {
    if (src.isDirectory()) {
        ftp.makeDirectory(src.getName());
        ftp.changeWorkingDirectory(src.getName());
        for (File file : src.listFiles()) {
            upload(file, ftp);
        }
        ftp.changeToParentDirectory();
    }
    else {
        InputStream srcStream = null;
        try {
            srcStream = src.toURI().toURL().openStream();
            ftp.storeFile(src.getName(), srcStream);
        }
        finally {
            IOUtils.closeQuietly(srcStream);
        }
    }
}
于 2013-06-24T11:47:39.783 回答