title: File Transfer not working smack 4.1 android
body: <p>Currently I am playing around with the new Smack 4.1 that offers full support for android. Sending and receiving messages is no problem, works fine. But now, I get stuck on sending and receiving Files. For example:</p>
  
  <h2>Send File</h2>
  
  <pre><code>public void sendFile(String fileName,String to){
  
          if(transferManager==null) {
              transferManager = FileTransferManager.getInstanceFor(mConnection);
  
          }
  
  
          OutgoingFileTransfer transfer = transferManager.createOutgoingFileTransfer(to);
  
          try {
  
              transfer.sendFile(new File(fileName), "This is a Test!");
          } catch (SmackException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <h2>Receive files</h2>
  
  <pre><code> public void setReceiveFileListener(){
  
  
          if(transferManager==null) {
              transferManager = FileTransferManager.getInstanceFor(mConnection);
          }
          transferManager.addFileTransferListener(new FileTransferListener() {
              @Override
              public void fileTransferRequest(FileTransferRequest request) {
                  IncomingFileTransfer transfer = request.accept();
  
                  try {
                      File file = new File(Environment.getExternalStorageDirectory()  + File.separator +"TEST"+File.separator+ "new.txt");
                      transfer.recieveFile(file);
  
                  } catch (SmackException | IOException e) {
                      e.printStackTrace();
  
                  }
              }
          });
  
      }
  </code></pre>
  
  <p>In this scenario, I just send a text file and want to save it as a new text file at sd card as "new.txt". The problem is not with the file itself, the file exists. Also, the receiver id is correct, it´s like "user@host.com/Smack" . That´s the same receiver which I can send normal messages successfully. </p>
  
  <h2>The error code I get from Smack:</h2>
  
  <p><strong>error 503 - service unavailable</strong></p>
  
  <p>This error respone I get directly from smack after sending file and it seems the file is not transferred, because the receiver listener shows nothing (I made Logs on both, sending and receiving), but listener is surely registerred.
  But I am totally sure, that File Transfer is supported by the server, it´s declared at their website www.coderollers.com . I´ve read many questions about here in SO and also at the Smack Developer Community. Nothing helped, so my question here is:</p>
  
  <ol>
  <li>What could be the cause of this problem?</li>
  <li>Could it be because I have to change the Port?</li>
  <li>How to change the port of an existing connection in smack?</li>
  <li>Any alternatives to file transport?</li>
  </ol>
  
  <p>My normal port is 5222, that works fine to send messages. I hope someone get it work and can lead me to the right directions....thanks for helping!</p>
  
  <h2>SOLUTION</h2>
  
  <p>For all who are interested: Devendra Singhs answer is correct, with a little note by myself. It seems to be important, which resource is used. From mobile to mobile, You have to use <strong>"mobile"</strong>. Wether "Smack" nor any other resource identifier would work here. So it is important to initialize the <code>OutgoingFileTransfer</code> correctly like this:</p>
  
  <pre><code>        OutgoingFileTransfer oft = ftm1.createOutgoingFileTransfer
  (XmppStringUtils.completeJidFrom(USER, SERV, "mobile"));//important resource "mobile"
  </code></pre>