2

FTP サーバーに .class ファイルをアップロードしています。アップロードされたファイルは空ではありませんが、逆コンパイルできないため、確実に破損しています。FTP サーバーに .class ファイルをアップロードする別の方法があると思われます。

スニペットは次のとおりです。

public boolean uploadFileOnFTPServer(File file, String uploadToPath) { 
    //file - File stored on local system that is to be uploaded on server
    //uploadToPath - Remote server path where the file is to be stored

    boolean isUploaded = false;
    try {
        FileInputStream inputStream = new FileInputStream(file);
       //InputStream inputStream = new FileInputStream(file);

        if (connectToFTPServer()) { // connectToFTPServer() - method to connect to server
            ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); // ftpClient is an object of FTPClient class

            if (ftpClient.login(userName, password)) {
                System.out.println("Logged in to server. Username: " + userName);
                if (ftpClient.changeWorkingDirectory(uploadToPath)) {
                    System.out.println("Navigated to path " + uploadToPath);                                                              

                    if (ftpClient.storeFile(file.getName(), inputStream)) {
                        inputStream.close();
                        System.out.println("File " + file.getName() + " uploaded to server.");
                        isUploaded = true;
                    }

                } 
        }
    } catch (Exception e) {
        strRemarks = "Exception reported: Unable to upload file. Error Details: " + e.toString();
        System.out.println(strRemarks);
        e.printStackTrace();
    } finally {
        disconnectFTPServer();
    }
    return isUploaded;
}
4

2 に答える 2

0

テキスト ファイルをバイナリ モードでアップロードして、実際に何が転送されるかを確認しましたか?

エンコーディングを指定することもお勧めします

client.setControlEncoding(encoding);
client.connect(host, port);

これは接続する前に行う必要があります。

于 2014-04-18T07:53:18.140 に答える