Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    [VB6]Invio file

    Ciao a Tutti
    devo creare un semplice programma client server che consente di inviare file dal client al server e il server accetta in automatico i file e li salva in una cartella
    come posso fare?

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Beh ... non e' semplice in una risposta ... in pratica puoi utilizzare il componente Winsock da un lato e dall'altro.

    Dal lato server, installi un programma che ascolta e che dispone delle necessarie autorizzazioni a scrivere file nel filesystem; dal lato client, esegui un programma che si collega al server su una porta prescelta.

    Ma se hai fatto questa domanda, sicuramente devi studiare un po' di TCP e connessioni client/server prima di scrivere ...

  3. #3
    grazie del consiglio

  4. #4
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    ciao,
    se ti accontenti di poco ecco cosa ci vuole:

    Server:

    codice:
    Option Explicit
    
    Dim lPos As Long
    Dim bOK As Boolean
    Dim fname As String
    
    Private Sub Form_Load()
    wsTCP(0).LocalPort = 1111
    wsTCP(0).Listen
    End Sub
    
    Private Sub wsTCP_Close(Index As Integer)
      Close #1
      Unload wsTCP(1)
      bOK = False
    End Sub
    
    Private Sub wsTCP_ConnectionRequest(Index As Integer, ByVal requestID As Long)
     Load wsTCP(1)
      wsTCP(1).Accept requestID
    End Sub
    
    Private Sub wsTCP_DataArrival(Index As Integer, ByVal bytesTotal As Long)
      If Not bOK Then
        wsTCP(1).GetData fname
        If InStr(fname, vbCrLf) <> 0 Then fname = Left(fname, InStr(fname, vbCrLf) - 1)
        bOK = True
        If Dir(App.Path & "\Down\" & fname) <> "" Then Kill App.Path & "\Down\" & fname
        Open App.Path & "\Down\" & fname For Binary As 1
        lPos = 1
        wsTCP(1).SendData "OK" & vbCrLf
      Else
        Dim buffer() As Byte
        wsTCP(1).GetData buffer
        Put #1, lPos, buffer
        lPos = lPos + UBound(buffer) + 1
     
      End If
    End Sub
    Client:

    codice:
    Option Explicit
    Dim buffer() As Byte
    Dim lBytes As Long
    Dim temp As String
    
    Private Sub cmdBrowse_Click()
      dlg.ShowOpen
      txtFile = dlg.FileName
    End Sub
    
    Private Sub cmdSend_Click()
      cmdSend.Enabled = False
      lBytes = 0
      DoEvents
      ReDim buffer(FileLen(dlg.FileName) - 1)
      Open dlg.FileName For Binary As 1
      DoEvents
      Get #1, 1, buffer
      Close #1
     Load wsTCP(1)
      wsTCP(1).Connect
      lblStatus = "Connecting..."
    End Sub
    
    Private Sub Form_Load()
    
      wsTCP(0).RemoteHost = "172.16.54.1"
      wsTCP(0).RemotePort = 1111
    End Sub
    
    Private Sub wsTCP_Close(Index As Integer)
      lblStatus = "Connection closed"
      Unload wsTCP(1)
    End Sub
    
    Private Sub wsTCP_Connect(Index As Integer)
      lblStatus = "Connected"
      wsTCP(1).SendData dlg.FileTitle & vbCrLf
    End Sub
    
    Private Sub wsTCP_DataArrival(Index As Integer, ByVal bytesTotal As Long)
      wsTCP(1).GetData temp
      
      If InStr(temp, vbCrLf) <> 0 Then temp = Left(temp, InStr(temp, vbCrLf) - 1)
      If temp = "OK" Then
        wsTCP(1).SendData buffer
      Else
        lblStatus = "Istruzione in Arrivo"
        Unload wsTCP(1)
        cmdSend.Enabled = True
      End If
    End Sub
    
    Private Sub wsTCP_SendComplete(Index As Integer)
      If temp = "OK" Then
        lblStatus = "Trasferimento completato"
        temp = ""
        Unload wsTCP(1)
        cmdSend.Enabled = True
      End If
    End Sub
    
    Private Sub wsTCP_SendProgress(Index As Integer, ByVal bytesSent As Long, ByVal bytesRemaining As Long)
      If temp = "OK" Then
      DoEvents
        lBytes = lBytes + bytesSent
        lblStatus = lBytes & " out of " & UBound(buffer) & " bytes sent"
      End If
    End Sub
    se hai difficoltà con i controlli, sono:

    lblStatus = Label
    wsTCP = Winsock
    due Command , uno lo chiami "cmdSend" l' altro "cmdBrowse", poi
    CommonDialog1 = dlg
    un textbox = txtFile

    Ciao

  5. #5
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303

    Re: [VB6]Invio file

    Originariamente inviato da pierfrancis
    Ciao a Tutti
    devo creare un semplice programma client server che consente di inviare file dal client al server e il server accetta in automatico i file e li salva in una cartella
    come posso fare?
    il codice che ti ho postato, prevede il salvataggio in una cartella chiamata "Down", per la questione in automatico dovresti specificare se il file da salvare è sempre lo stesso? se si dovresti inserire un timer dove all' interno di un tot di minuti o secondi scateni l' evento.
    Ciao

  6. #6
    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.