powered by Jive Software

FileTransferManager.addFileTransferListener is never called


I couldn’t find a relevant reply. I 'm developing a standalone Java test application using smack 4.3.4. I use In-Band for file transfers:

FileTransferManager fileTransferManager = FileTransferManager.getInstanceFor(connection);
        FileTransferNegotiator.IBB_ONLY = true;
        OutgoingFileTransfer fileTransfer = null;
        try {
            fileTransfer = fileTransferManager.createOutgoingFileTransfer(JidCreate.entityFullFrom(buddyJID + "/Spark"));
        } catch (XmppStringprepException ex) {
            LOG.log(Level.SEVERE, null, ex);
       if (fileTransfer != null) {
           try {
                    fileTransfer.sendFile(file, "sending attachment...");
                } catch (SmackException ex) {
                    LOG.log(Level.SEVERE, null, ex);

I monitor the file transfer and it is sent correctly. When my user(s) connect and login to Openfire, I add a listener to listen to file transfers:

final FileTransferManager manager = FileTransferManager.getInstanceFor(connection);
//        FileTransferNegotiator.setServiceEnabled(connection, true);   
        manager.addFileTransferListener((FileTransferRequest request) -> {
            // Check to see if the request should be accepted
            if (request.getFileName() != null) {
                try {
                    // Accept it
                    IncomingFileTransfer transfer = request.accept();
//                    monitorFileTransfer(transfer, "");
                    try (InputStream fileReceived = transfer.receiveFile();
                            BufferedInputStream bis = new BufferedInputStream(fileReceived)) {
              } else {
                try {
                    // Reject it
                    LOG.warning("File rejected " + request.getFileName());
                } catch (SmackException.NotConnectedException | InterruptedException ex) {
                    LOG.log(Level.SEVERE, null, ex);

However, the listener is never called. Do I need to add the listener at a specific moment? Is there something else I 've been missing? The results is that the file transfers are being sent to Openfire and are never consumed.

Is there a working example? My code is based on the documentation example.

Thank you in advance for your prompt reply.

Unfortunately your post does not contain enough information to provide any assistance. Please have a look at https://github.com/igniterealtime/Smack/wiki/How-to-ask-for-help,-report-an-issue-and-possible-solve-the-problem-yourself

Thank you for your reply. However, I have reported according to the guidelines you mention.

  • The Smack version (e.g. obtained via SmackConfiguration.getVersion() ) ==> 4.3.4 already mentioned
  • The exception and the full stacktrace (if applicable). Note that some exceptions, e.g. plain SmackException or ExecutionException, wrap the causing exception. Make sure to take those into consideration. ==> No exception
  • An XMPP trace of the exchanged stream elements between client and server, which can be obtained by setting SmackConfiguration.DEBUG ( DEBUG_ENABLED in older Smack versions) to true . ==> I missed; I present it below
  • The relevant code parts (please do not post whole source files!) ==> already mentioned in my original post

https://github.com/igniterealtime/Smack/wiki/Smack-XMPP-File-Transfer refers to broken link MAXS Transport XMPP I 'm afraid.

INFO: Initializing connection to server localhost port 5222 [Wed Apr 29 15:36:25 CEST 2020]
INFO: Connected: true [Wed Apr 29 15:36:45 CEST 2020]
INFO: user001 authenticated? true [Wed Apr 29 15:36:46 CEST 2020]
INFO: Sending attachment 'test.txt' to user user002@localhost [Wed Apr 29 15:36:55 CEST 2020]
INFO: status is:Initial [Wed Apr 29 15:36:55 CEST 2020]
INFO: status is:Initial [Wed Apr 29 15:36:55 CEST 2020]
INFO: File transfer status: Negotiating Transfer, progress: 0.0 [Wed Apr 29 15:36:55 CEST 2020]
INFO: test.txt has been successfully transferred. [Wed Apr 29 15:36:56 CEST 2020]
INFO: The file transfer is done. [Wed Apr 29 15:36:56 CEST 2020]
INFO: Attachment test.txt sent from user001@localhost to user002@localhost [Wed Apr 29 15:36:56 CEST 2020]

Regarding smack debug, I 'm not sure what to post. These are the last stanzas:

<iq xmlns="jabber:client" to="user001@localhost/aktuu2n806" from="localhost" id="679-1085" type="get">
  <query xmlns="jabber:iq:version"/>
<iq xmlns="jabber:client" to="localhost" id="679-1085" type="error">
  <error xmlns="jabber:client" type="modify">
    <not-acceptable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>

The file transfer was not actually happening this is why the listener was listening but wa receiving nothing.

To send a file you need the full JID of the recipient. If you use smack, there is no physical XMPP client (like spark). In that case you use “Smack” or “Resource” (see here).

fileTransfer = fileTransferManager.createOutgoingFileTransfer(JidCreate.entityFullFrom(buddyJID + "/Smack")));

However, I still get an error:

XMPP error reply received from user002@localhost/Smack: XMPPError: not-allowed - cancel

And of course the problem had nothing to do with smack. The issue was that the tool I have created was reading and writing to the same file, as a result, the file was erased and the error was because smack was requested to transfer an empty file. So, if you see this error, check the file you try to transfer first; it might have 0 bytes.

1 Like

Hm, we might consider adding a check with a more descriptive error message in such case… Thanks for doing the research :slight_smile:

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.