Results 1 to 7 of 7

Thread: copying files to a remote server

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    copying files to a remote server

    Hello,

    I have to develop a program that will allow a user to enter a url of a remote server and then copy files there.

    I am not sure to get started with this, can anyone point me in the right direction.

    Many thanks for any advice,

    Steve
    steve

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: copying files to a remote server

    Server? What kind of server? On your local network? An ftp server? ("Server" just means it's a computer with a program that's looking for incoming requests on some port.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: copying files to a remote server

    Hello,

    Maybe I should have been more specific it could be either a web server (port 80) or a ftp server (port 21).

    Thanks for any ideas that you can give me.

    Steve
    steve

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: copying files to a remote server

    You can use either the Inet control, Winsock control, or the Winsock API functions.

    Files uploaded to a web server are usually done so via FTP. Otherwise they are usually posted to a PHP script via the HTTP POST method. You can do this with Inet pretty easily, there is a lot of code on the net and these forums for this.

    Winsock gives you much more control over everything, but if all you want to do is upload files the easy way then Inet is probably your best bet.

  5. #5
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: copying files to a remote server

    you can use this function to upload a file with the Inet control via FTP. The server must be running as an FTP server in order for it to accept the files.

    VB Code:
    1. Private Sub Command1_Click()
    2. 'Upload the file
    3.  
    4. Dim Server As String, Username As String, Password As String, LocalName As String, RemoteName As String
    5.  
    6. Server = "ftp.somewhere.com"
    7. Username = "the182guy"
    8. Password = "password182"
    9.  
    10. LocalName = App.Path & "\IP_Address.txt" 'give it the location of the file to upload
    11. RemoteName = "IP_Address.txt" 'once upload the file will be named this
    12.  
    13.  If UploadFile(Inet1, Server, Username, Password, Chr(34) & LocalName & Chr(34), RemoteName) = True Then
    14.     MsgBox "Upload complete", vbInformation
    15.  Else
    16.     MsgBox "error file did not uplaod", vbExclamation
    17.  End If
    18.  
    19. End Sub
    20.  
    21. Public Function UploadFile(Inet As Inet, ByVal HostName As String, ByVal Username As String, ByVal Password As String, ByVal LocalFileName As String, ByVal RemoteFileName As String) As Boolean
    22. 'This is the function used to upload the file
    23.  
    24. Inet1.Protocol = icFTP 'set the inet to FTP protocol
    25. Inet1.RemoteHost = HostName$ 'set the server
    26. Inet1.Username = Username$ 'set username
    27. Inet1.Password = Password$ 'set password
    28. Inet1.Execute Inet1.URL, "Put " + LocalFileName$ + " " + RemoteFileName$ 'upload the file
    29.  Do While Inet1.StillExecuting 'loop while waiting
    30.  DoEvents
    31.  Loop
    32. UploadFile = (Inet1.ResponseCode = 0) 'return boolean
    33.  
    34. End Function
    Chris

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: copying files to a remote server

    For servers supporting WebDAV (and probably Frontpage Server Extensions) there is another way.

    This method uses the capabilities of ADO 2.5 or later and the OLEDB Provider for Internet Publishing. Windows 2000 and later come with this Provider, and installing IE 5.0 or later adds (or updates) it as needed.

    While the documentation seems pretty good in general there is a dearth of working examples of uploading a file this way. I've attached a small example that tests out fine here. The web server WebDAV folder URL and file to send are hard-coded but these can easily be accepted from the user as well as User/PW.

    This code should also work with servers that have Frontpage Server Extensions but I haven't tested it. Of course the security at the server must allow WebDAV writes to the target folder.

    VB Code:
    1. Private Sub Command1_Click()
    2.     'Write file "test.htm" from current directory
    3.     'to WebDAV folder TestDir on server BigDog
    4.     'with overwrite.
    5.     Dim recDir As New ADODB.Record
    6.     Dim stmData As New ADODB.Stream
    7.    
    8.     recDir.Open "test.htm", "URL=http://BigDog/TestDir", _
    9.                 adModeReadWrite, _
    10.                 adCreateNonCollection Or adCreateOverwrite, _
    11.                 adDelayFetchStream, _
    12.                 Text1(0).Text, _
    13.                 Text1(1).Text
    14.     Print "* Record opened to web server"
    15.     With stmData
    16.         .Type = adTypeBinary 'Sample is ANSI text but avoid adding BOM.
    17.         .Open recDir, adModeWrite, adOpenStreamFromRecord
    18.         Print "* Stream opened to web server"
    19.         .LoadFromFile "test.htm"
    20.         Print "* Local file loaded into Stream"
    21.         .Close
    22.         Print "* File saved to web server"
    23.     End With
    24.     recDir.Close
    25.     Print "* Complete"
    26.     Command2.SetFocus
    27. End Sub
    Last edited by dilettante; Feb 1st, 2007 at 07:53 PM.

  7. #7
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: copying files to a remote server

    Use Winsock or Inet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width