0

这是我的问题。我正在尝试将文件从本地上传到远程 ftp 服务器。但我收到连接超时异常或文件无法上传。如果我在本地执行它,它可以工作,但对于远程服务器它不会。我正在尝试以被动模式上传文件。

如果我尝试;

ftpClient.enterLocalPassiveMode(); //it gives timeout error,

ftpClient.enterRemotePassiveMode(); //it gives files could not upload.

我在 Windows 防火墙中为双方(我的本地和远程服务器)组织了 filezilla 设置。这是我的一段代码;

FTPClient ftpClient = new FTPClient();

try {

    // connect and login to the server
    ftpClient.connect(server, port);
    ftpClient.login(user, pass);
    // use local passive mode to pass firewall
    ftpClient.enterLocalPassiveMode();
    System.out.println("Connected");

    String remoteDirPath = "/Upload";
    String localDirPath = "C:/Users/nexgen/workspace/codes/pak";
    FTPUtil.uploadDirectory(ftpClient, remoteDirPath, localDirPath, "");

    // log out and disconnect from the server
    ftpClient.logout();
    ftpClient.disconnect();

    System.out.println("Disconnected");
} catch (IOException ex) {
    ex.printStackTrace();
}

亲切的问候。

4

0 回答 0