Announcement

Collapse
1 of 2 < >

Announcement

2 of 2 < >

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

gbNetBoard - Internet Clipboard

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • gbNetBoard - Internet Clipboard



    When modifying a new Win10 PC for a customer (adding additional hardware and software) I like to minimize the software I add to the new PC. I also prefer not to attach the new PC to my home-office LAN.

    There are times, however, when I want to transfer text/images from my home-office PC to the new Win10 PC. For that, I wrote gbNetBoard, an "internet clipboard", that lets me move information from the clipboard on one PC to the clipboard on another PC.

    gbNetBoard actually consists of 2 apps - gbPut and gbGet, whose functions match their names.

    On the sending PC, the user places text/images on the clipboard, then gbPut captures/sends that information to a server.

    On the receiving PC, gbGet downloads the server information and places it on the receiving PC's clipboard.

    That effectively creates an internet clipboard, where one PC copies text/images from its clipboard to the internet clipboard. Then on another PC the information is made available for pasting from the second PC's clipboard.

    v2.0 now available. It allows you to transfer a file by dropping the file on gbPut. When gbGet is used, the receiving PC folder containing the copy of the file is opened. The transferred file is not put on the receiving PC clipboard.

    Online help is at http://www.garybeene.com/sw/gbnetboard.htm.
    Download the source code, EXEs and image files here.
    A discussion thread for gbNetBoard is here.

    gbPut Source Code:
    Code:
    #Compile Exe
    #Dim All
    
    #Debug Display On
    #Debug Error On
    
    $Ver = "2.0"
    
    %Unicode=1
    #Include "Win32API.inc"
    
    #Resource Icon Logo, "icons/up.ico"
    Global FTPSite$, FTPSiteFolder$, User$, PSW$, HTTPPath$
    
    Function PBMain() As Long
       Local temp$, BitmapResult, TextResult As Long,hBMP As Dword, BinaryFileName$, LocalFileName$
    
       GetFTPSettings
       If IsFolder (Exe.Path$ + "temp") = %False Then MkDir Exe.Path$ + "temp"
    
       'if there is one, place the binary file name on the FTP server in a
       BinaryFileName$ = Exe.Path$ + "temp\binaryfilename.txt"  'the filename on the FTP server containing the binary file name
       If Len(Command$) Then
          LocalFileName$ = Command$
          Open BinaryFileName$ For Output As #1 : Print #1, PathName$(Namex,LocalFileName$); : Close #1
          FTPPut BinaryFileName$
          FTPPut LocalFileName$
          WinBeep(300,500)       'just to say I'm done
          If IsFile(BinaryFileName$) Then Kill BinaryFileName$  'remove text file containing the name of the binary file
          Exit Function
       Else
          Open BinaryFileName$ For Output As #1 : Print #1, $Spc; : Close #1   'create 1-byte file
          FTPPut BinaryFileName$
          If IsFile(BinaryFileName$) Then Kill BinaryFileName$  'remove text file containing the name of the binary file
       End If
    
       'figure out what kind of information is on the local clipboard
       Clipboard Get Bitmap To hBMP, BitmapResult
       Clipboard Get Text To temp$, TextResult
       LocalFileName$ = Exe.Path$ + "temp\clipboard.dat"  'will contain a bitmap or text, whichever is found in clipboard
       If BitmapResult Then
          'bitmap found on clipboard - save to file then send to server
          Graphic Attach hBMP, 0
          Graphic Save LocalFileName$  'file is a *.bmp. will rename when download
          FTPPut LocalFileName$
       ElseIf TextResult Then
          'text found on clipboard - save to file then send to server
          Open LocalFileName$ For Output As #1 : Print #1, temp$; : Close #1
          FTPPut LocalFileName$
       Else
          'something other than text or bitmap was found - take no action
          MsgBox "Clipboard content is not text or bitmap!", %MB_Ok Or %MB_IconInformation, "gbInternetClipboard"
       End If
       If IsFile(LocalFileName$) Then Kill LocalFileName$  'remove temporary clipboard content file
       WinBeep(300,500)       'just to say I'm done
    End Function
    
    Sub FTPPut(FTPFileName$)
       'Stuart McLachian
       Local q As String * 1, ff As Long, FTPCommandsFileName$
       q= """"
       'run command line FTP
       FTPCommandsFileName$ = "FTPCommands.txt"
       Open FTPCommandsFileName$ For Output As #1
       Print #1, "open " + FTPSite$
       Print #1, User$
       Print #1, PSw$
       Print #1, "cd " & FTPSiteFolder$
       Print #1, "lcd " & q & Exe.Path$ & q
       Print #1, "binary"
       Print #1, "put " & q & FTPFileName$ & q
       Print #1, "bye"
       Close #1
    
       Shell "ftp.exe -s:" + FTPCommandsFileName$, 0
       If IsFile(FTPCommandsFileName$) Then Kill FTPCommandsFileName$   'optional to remove temporary FTP commands file
    End Sub
    
    Sub GetFTPSettings
       Open Exe.Path$ + "ftpsettings.txt" For Input As #1
       Line Input #1, HTTPPath$           'HTTP download path for gbGet
       Line Input #1, FTPSite$            'FTP site, such as ftp.webhero.com
       Line Input #1, FTPSiteFolder$      'FTP site folder, such as /public_html/clipboard/
       Line Input #1, User$               'FTP logon user name
       Line Input #1, PSW$                'FTP logon password
       Close #1
    End Sub
    gbGet Source Code
    Code:
    #Compile Exe
    #Dim All
    
    #Debug Display On
    #Debug Error On
    
    $Ver = "2.0"
    
    %Unicode=1
    #Include "Win32API.inc"
    #Include "WinINET.inc"
    
    #Resource Icon Logo, "icons/down.ico"
    Global FTPSite$, FTPSiteFolder$, User$, PSW$, HTTPPath$
    
    Function PBMain() As Long
       Local LocalFileNamePath, LocalFilePath, BinaryHTTPPath As WStringZ*%Max_Path, iResult As Long
       Local BinaryFilepath$, BinaryFileName$, temp$, hBMP As Dword
    
       If IsFolder (Exe.Path$ + "temp") = %False Then MkDir Exe.Path$ + "temp"
       GetFTPSettings
    
       LocalFileNamePath   = Exe.Path$ + "temp\binaryfilename.txt
       BinaryHTTPPath  = Left$(HTTPPath$, InStr(-1,HTTPPath$,"/")) + "binaryfilename.txt"
    
       DeleteURLCacheEntry(BinaryHTTPPath)   'clear the cache
       If URLDownloadToFile (Nothing, BinaryHTTPPath, LocalFileNamePath, 0, Nothing) = 0 Then
          Open LocalFileNamePath For Input As #1 : Line Input #1, BinaryFileName$ : Close #1
          If IsFile(LocalFileNamePath) Then Kill LocalFileNamePath
          If Len(Trim$(BinaryFileName$)) Then
             LocalFilePath  = Exe.Path$ + "temp\" + BinaryFileName$
             BinaryHTTPPath = Left$(HTTPPath$, InStr(-1,HTTPPath$,"/")) + BinaryFileName$
             DeleteURLCacheEntry((BinaryHTTPPath))   'clear the cache
             URLDownloadToFile (Nothing, BinaryHTTPPath, LocalFilePath, 0, Nothing)
             ShellExecute 0, "Open", PathName$(Path,LocalFilePath), $Nul, $Nul, %SW_Restore
             WinBeep (300,500)
             Exit Function
          Else
             'no binary file (a binary file may exist on the server but is not the the last file uploaded)
          End If
       Else
          WinBeep(300,500)
          MsgBox "gbInternetClipboard data type unknown!", %MB_Ok Or %MB_IconInformation, "gbInternetClipboard"
          Exit Function
       End If
    
       LocalFilePath = Exe.Path$ + "temp\clipboard.dat"
       DeleteURLCacheEntry((HTTPPath$))   'clear the cache
       If URLDownloadToFile (Nothing, (HTTPPath$), LocalFilePath, 0, Nothing) = 0 Then
          Open LocalFilePath For Binary As #1
          Get$ #1, Lof(1), temp$
          Close #1
          Clipboard Reset
          If Left$(temp$,2) = "BM" Then
             Graphic Bitmap Load LocalFilePath, 0, 0 To hBMP   'put bitmap on clipboard
             Clipboard Set Bitmap hBMP
          Else
             Clipboard Set Text temp$                      'put text on clipboard
          End If
          WinBeep(300,500)                                 'just to say I'm done
          If IsFile(LocalFilePath) Then Kill LocalFilePath
       Else
          MsgBox "gbInternetClipboard text file not found!", %MB_Ok Or %MB_IconInformation, "gbInternetClipboard"
       End If
    End Function
    
    Sub GetFTPSettings
       Open Exe.Path$ + "ftpsettings.txt" For Input As #1
       Line Input #1, HTTPPath$           'HTTP download path for gbGet
       Line Input #1, FTPSite$            'FTP site, such as ftp.webhero.com
       Line Input #1, FTPSiteFolder$      'FTP site folder, such as /public_html/clipboard/
       Line Input #1, User$               'FTP logon user name
       Line Input #1, PSW$                'FTP logon password
       Close #1
    End Sub

    Last edited by Gary Beene; 11 Jan 2017, 11:40 AM. Reason: Source Code updated to v2.0 - supports file transfer.
Working...
X