Receive-a-file-using-XMPP-Jabber-protocol - WeOnlyDo Software example code



All

wodCrypt (12)
wodSSH (10)
wodSFTP (23)
wodSSHServer (1)
wodSSHTunnel (11)
wodSSHpackage
wodSFTPdll

wodSSH.NET (10)
wodSFTP.NET (24)
wodFtpDLX.NET (22)
wodWebServer.NET (10)

wodAppUpdate (13)
wodHttpDLX (8)
wodFtpDLX (22)
wodTelnetDLX
wodFTPServer (3)
wodWebServer (10)
wodVPN
wodXMPP (13)
All ** [Visual Basic] ** [C#] ** [VB.NET] **

Receive a file using XMPP/Jabber protocol
VB code
Dim WithEvents wodXMPP1 As wodXMPPCom
Private Sub Form_Load()
    Set wodXMPP1 = New wodXMPPCom
    
    wodXMPP1.Login = "JID__username@domain.com"
    wodXMPP1.Password = "JID__password"
    wodXMPP1.UseUPnP = True 'use UPnP for firewalls.
    'Connect to Jabber/XMPP server.
    wodXMPP1.Connect
End Sub

'Connected Event fires when wodXMPP connects to remote server.
Private Sub wodXMPP1_Connected()
    MsgBox "Connected"
End Sub

'Disconnected Event fires when wodXMPP disconnects from server.
Private Sub wodXMPP1_Disconnected(ByVal ErrorCode As Long, ByVal ErrorText As String)
    'Inside Disconnected Event we can check for an error using ErrorText and ErrorCode variable.
    If ErrorCode <> 0 Then
        MsgBox "Error: " & ErrorText
    End If
End Sub

'FileTransferStart Event fires when file transfer starts.
Private Sub wodXMPP1_FileTransferStart(ByVal Contact As WODXMPPCOMLib.IXMPPContact, ByVal File As WODXMPPCOMLib.IXMPPFile, Action As WODXMPPCOMLib.XMPPActionsEnum)
    'When some contact send a file to us. We will receive information about that file inside YesNo message box.
    'We can then decide if we want to accept that file or not.
    If MsgBox("Contact: " & Contact.JID & vbCrLf & "Filename: " & File.Name & vbCrLf & "File Size: " & File.Size & " bytes" & vbCrLf & "File Description: " & File.Description, vbYesNo + vbQuestion, "Accept file?") = vbYes Then
        'Save received file to some place on your machine.
        File.Name = "C:\" & File.Name
        Action = Allow
    Else
        Action = Deny
    End If
End Sub

'FileTransferProgress Event fires during file transfer.
Private Sub wodXMPP1_FileTransferProgress(ByVal Contact As WODXMPPCOMLib.IXMPPContact, ByVal File As WODXMPPCOMLib.IXMPPFile, ByVal Position As Long)
    Debug.Print Position & " / " & File.Size
End Sub

'FileTransferEnd Event fires when file transfer completes.
Private Sub wodXMPP1_FileTransferEnd(ByVal Contact As WODXMPPCOMLib.IXMPPContact, ByVal File As WODXMPPCOMLib.IXMPPFile, ByVal ErrorCode As Long, ByVal ErrorText As String)
    'We can check here for errors that is received during file transfer.
    If ErrorCode <> 0 Then
        MsgBox "FileTransfer Error: " & ErrorText
    Else
        MsgBox "File transfer finished!"
    End If
End Sub
VB.NET code
Dim WithEvents wodXMPP1 As WODXMPPCOMLib.wodXMPPCom
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    wodXMPP1 = New WODXMPPCOMLib.wodXMPPCom

    wodXMPP1.Login = "JID__username@domain.com"
    wodXMPP1.Password = "JID__password"
    wodXMPP1.UseUPnP = True 'use UPnP for firewalls.
    'Connect to Jabber/XMPP server.
    wodXMPP1.Connect()
End Sub

'Connected Event fires when wodXMPP connects to remote server.
Private Sub wodXMPP1_Connected() Handles wodXMPP1.Connected
    MsgBox("Connected")
End Sub

'Disconnected Event fires when wodXMPP disconnects from server.
Private Sub wodXMPP1_Disconnected(ByVal ErrorCode As Integer, ByVal ErrorText As String) Handles wodXMPP1.Disconnected
    'Inside Disconnected Event we can check for an error using ErrorText and ErrorCode variable.
    If ErrorCode <> 0 Then
        MsgBox("Error: " & ErrorText)
    End If
End Sub

'FileTransferStart Event fires when file transfer starts.
Private Sub wodXMPP1_FileTransferStart(ByVal Contact As WODXMPPCOMLib.XMPPContact, ByVal File As WODXMPPCOMLib.XMPPFile, ByRef Action As WODXMPPCOMLib.XMPPActionsEnum) Handles wodXMPP1.FileTransferStart
    'When some contact send a file to us. We will receive information about that file inside YesNo message box.
    'We can then decide if we want to accept that file or not.
    If MsgBox("Contact: " & Contact.JID & vbCrLf & "Filename: " & File.Name & vbCrLf & "File Size: " & File.Size & " bytes" & vbCrLf & "File Description: " & File.Description, vbYesNo + vbQuestion, "Accept file?") = vbYes Then
        'Save received file to some place on your machine.
        File.Name = "C:\" & File.Name
        Action = WODXMPPCOMLib.XMPPActionsEnum.Allow
    Else
        Action = WODXMPPCOMLib.XMPPActionsEnum.Deny
    End If
End Sub

'FileTransferProgress Event fires during file transfer.
Private Sub wodXMPP1_FileTransferProgress(ByVal Contact As WODXMPPCOMLib.XMPPContact, ByVal File As WODXMPPCOMLib.XMPPFile, ByVal Position As Integer) Handles wodXMPP1.FileTransferProgress
    Console.WriteLine(Position & " / " & File.Size)
End Sub

'FileTransferEnd Event fires when file transfer completes.
Private Sub wodXMPP1_FileTransferEnd(ByVal Contact As WODXMPPCOMLib.XMPPContact, ByVal File As WODXMPPCOMLib.XMPPFile, ByVal ErrorCode As Integer, ByVal ErrorText As String) Handles wodXMPP1.FileTransferEnd
    'We can check here for errors that is received during file transfer.
    If ErrorCode <> 0 Then
        MsgBox("FileTransfer Error: " & ErrorText)
    Else
        MsgBox("File transfer finished!")
    End If
End Sub
C# code
WODXMPPCOMLib.wodXMPPCom wodXMPP1;
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    wodXMPP1 = new WODXMPPCOMLib.wodXMPPCom();
    wodXMPP1.Connected += new WODXMPPCOMLib._IwodXMPPComEvents_ConnectedEventHandler(wodXMPP1_Connected);
    wodXMPP1.Disconnected += new WODXMPPCOMLib._IwodXMPPComEvents_DisconnectedEventHandler(wodXMPP1_Disconnected);
    wodXMPP1.FileTransferStart += new WODXMPPCOMLib._IwodXMPPComEvents_FileTransferStartEventHandler(wodXMPP1_FileTransferStart);
    wodXMPP1.FileTransferProgress += new WODXMPPCOMLib._IwodXMPPComEvents_FileTransferProgressEventHandler(wodXMPP1_FileTransferProgress);
    wodXMPP1.FileTransferEnd += new WODXMPPCOMLib._IwodXMPPComEvents_FileTransferEndEventHandler(wodXMPP1_FileTransferEnd);

    wodXMPP1.Login = "JID__username@domain.com";
    wodXMPP1.Password = "JID__password";
    wodXMPP1.UseUPnP = true; //use UPnP for firewalls.
    //Connect to Jabber/XMPP server.
    wodXMPP1.Connect(null);
}

//Connected Event fires when wodXMPP connects to remote server.
private void wodXMPP1_Connected()
{
    MessageBox.Show("Connected");
}

//Disconnected Event fires when wodXMPP disconnects from server.
private void wodXMPP1_Disconnected(int ErrorCode, string ErrorText)
{
    //Inside Disconnected Event we can check for an error using ErrorText and ErrorCode variable.
    if (ErrorCode != 0)
    {
        MessageBox.Show("Error: " + ErrorText);
    }
}

//FileTransferStart Event fires when file transfer starts.
private void wodXMPP1_FileTransferStart(WODXMPPCOMLib.XMPPContact Contact, WODXMPPCOMLib.XMPPFile File, ref WODXMPPCOMLib.XMPPActionsEnum Action)
{
    //When some contact send a file to us. We will receive information about that file inside YesNo message box.
    //We can then decide if we want to accept that file or not.
    if (MessageBox.Show("Contact: " + Contact.JID + "\r\nFilename: " + File.Name + "\r\nFile Size: " + File.Size + " bytes\r\nFile Description: " + File.Description, "Accept File?", MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        //Save received file to some place on your machine.
        File.Name = "C:\\" + File.Name;
        Action = WODXMPPCOMLib.XMPPActionsEnum.Allow;
    }
    else
    {
        Action = WODXMPPCOMLib.XMPPActionsEnum.Deny;
    }
}

//FileTransferProgress Event fires during file transfer.
private void wodXMPP1_FileTransferProgress(WODXMPPCOMLib.XMPPContact Contact, WODXMPPCOMLib.XMPPFile File, int Position)
{
    Console.WriteLine(Position + " / " + File.Size);
}

//FileTransferEnd Event fires when file transfer completes.
private void wodXMPP1_FileTransferEnd(WODXMPPCOMLib.XMPPContact Contact, WODXMPPCOMLib.XMPPFile File, int ErrorCode, string ErrorText)
{
    //We can check here for errors that is received during file transfer.
    if (ErrorCode != 0)
    {
        MessageBox.Show("FileTransfer Error: " + ErrorText);
    }
    else
    {
        MessageBox.Show("File transfer finished!");
    }
}