Results 1 to 27 of 27

Thread: Transfer file to Remote Server

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Transfer file to Remote Server

    Hi guys, how to transfer file to a remote server? What should i use? FTP, HTTP or Winsock?

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    Is your remote server an FTP server site or is it some other type of server?

    Using some FTP API's is probably the easiest. Less overhead as the FTP commands are already built in to the APIs. Winsock is OK if you don't mind going through all the login steps and then you will have to use two Winsock controls; one to send the FTP commands and receive Server responces and the other to send and receive file data. I'm not sure that you can use HTTP to send files to a remote server.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Transfer file to Remote Server

    I guess our technical can configure it to be an FTP server. What is the difference of using FTP vs HTTP. Ive already used HTTP transfer on vb.net but not in vb6.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Transfer file to Remote Server

    most severs are not set up to receive http file transfers, hence ftp where you have to login is more common

    there is code in this forum that should do http file transfers, but i have never been able to make it work, which i assume is a problem with the setup of my server

    you can use a shell object for the most simple ftp file transfer
    vb Code:
    1. dim initdir as variant
    2. initdir = "ftp://user:password@www.myserver.com.au/myfolder"
    3. Set sh = CreateObject("shell.application")
    4. Set n = sh.namespace(initdir)
    5. n.copyhere filepath\name   ' can be file or folder
    change username, password and server to suit, if you use a variable to for the filename, it should also be variant
    Last edited by westconn1; May 10th, 2011 at 11:22 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    What is the difference of using FTP vs HTTP.

    HTTP is a protocol language specifically designed for manipulating hypertext (HTML, for example) for the making of Web pages that are transfered to one or more cumputers from the server known as the HTTP server. HTTP servers, as a rule, do not allow for the transfer of data from the client to the HTTP server.

    FTP is also a protocol language specifically designed for the transfering of files from one computer to another where one computers runs an FTP server and the other an FTP client application. It can be a very complex language and somewhat difficult to deal with if you intend to do raw FTP command level programming. FTP is the command level and it must have a wrapper or shell program to run it.

    Winsock is not a language but rather a method for connecting one or more computers to one or more other computers. Using Winsock you can do a varity of things (like making a chat application) and of course send files to one or another computer using your own protocol. Winsock can be used to connect to an FTP server and send to that server FTP commands to send and or receive files and more. Using this approach you need to know both the Winsock methods and functions as well as knowing the FTP language. It requires two Winsock sockets. One socket is used to send FTP commands to the server and the other socket is used to send and receive data.

    For very simple file transfers to a remote server (and the remote server must understand the protocol you are using which probably is FTP) it would be best to use FTP APIs in your VB program or use the shell method as westconn1 suggested.

    Windows has a commandline application called ftp.exe which is a wrapper for FTP protocol which you can use to also send a file to a remote server as long as the server is an FTP server. You can shell this executable from within your VB program and use it to do your FTP work for you.

    I don't know how sophisicated you want to get or how elaborate an application you want to build but I think your three choises are already given.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transfer file to Remote Server

    I think some questions that could be useful might be:
    • Remote? How remote? On your LAN or across the Internet?
    • What does the server support already?

    If the server is on your LAN just use it as a file server.

    If it is across the Internet this isn't practical. However FTP has its problems too, especially firewall issues.

    Simple HTTP posts might be a solution but not a very general one.

    If this is a Windows server it is possible to configure IIS to support WebDAV shares by adding an extension. This can be used at client systems via the WebDAV Redirector built into Windows, which even allows you to make a drive letter to a WebDAV share. Based on the security assigned you can read, write, and copy files as well as get a directory listing.
    Code:
    C:\Users\Fiddler23>net use z: https://some.server.com/fileshare
    Enter the user name for 'some.server.com': FidMan
    Enter the password for 'some.server.com: xxxxxxxxxxx
    The command completed successfully.
    
    C:\Users\Fiddler23>dir z:
     Volume in drive Z has no label.
     Volume Serial Number is 0000-0000
    
     Directory of Z:\
    
    05/22/2010  09:03 PM    <DIR>          .
    05/22/2010  09:03 PM    <DIR>          ..
    12/30/2010  01:09 PM                35 Fred.nam
    11/17/2010  06:01 PM                35 Bob.nam
    04/15/2011  07:35 AM               111 junk.txt
    12/30/2010  01:08 PM                31 George.nam
                   4 File(s)            212 bytes
                   2 Dir(s)  145,922,428,928 bytes free
    You can also map the "drive" via Explorer or from within a program.

    I have no idea why anyone would think HTTP is only used for Web browsing. This hasn't been true for more than a decade.
    Last edited by dilettante; May 11th, 2011 at 06:45 AM.

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    I have no idea why anyone would think HTTP is only used for Web browsing.

    Can you post an example where one can use HTTP for sending a file to the server?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transfer file to Remote Server

    Quote Originally Posted by jmsrickland View Post
    Can you post an example where one can use HTTP for sending a file to the server?


    What do you think happens when you upload an attachment here?

    WebDAV also uses HTTP as its transport.

    You can create Web Services which can accept a file, etc.

    Then you have BITS which is how Microsoft delivers updates, etc.

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    Same question. Show an example, please.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transfer file to Remote Server

    Quote Originally Posted by jmsrickland View Post
    Same question. Show an example, please.
    Holy cow. This should have been plenty of information.

    You can map a WebDAV share outside the program by hand or you can use Shell or WScript objects or API calls to do it in the program.

    After that it's just a FileCopy statement. You can even open, read, write, kill, etc. files using regular old VB6 I/O statements. And it all happens over HTTP.

    The attached demonstration shows the use of the API calls to map and unmap the share. Won't do you much good without a WebDAV account somewhere but there are tons of free sites and you can always set up IIS for WebDAV to test locally.
    Attached Files Attached Files

  11. #11
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    Well, I'm not going to install IIS nor use WebDAV.

    I just wanted a simple example in VB code only that uses HTTP to send a file to an HTTP server. I'm not arguing with you about HTTP; I would just like to see a very simple example that I can compile and run and send a file to an HTTP server on the web. If you don't want to do it then OK.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transfer file to Remote Server

    Maybe start your own thread.

    Besides, WebDAV works just fine for what you ask. The server just needs to support it, as many do. Just not the cheapies.

  13. #13
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    The reason I asked for a VB code example is to have it so I can add it to my VB code database that I keep next to me. I have an example of a transfer from the server to to client using HTTP but I dont have one that sends to the server. The other reason is that the way you were suggesting won't tell me how to do it in VB. I know that an HTTP server has the ability to receive a file but that doesn't tell me how it's done. When you do use an HTTP server to receive your file exactly where will it be saved?

    Anyway, no problem.
    Last edited by jmsrickland; May 11th, 2011 at 02:36 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  14. #14
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transfer file to Remote Server

    The point is that there is no such thing as "an HTTP server" any more than a "TCP server."

    There is always some protocol used on top of this, making it a BITS server, FPSE server, WebDAV server, Web server, Web Services server, etc.


    Since you are talking about Web servers, there is no way to just "send a file" to them. When you upload a file to a post here for example, a posting acceptor is used at the Web server to accept <input type=file> form element input send via an HTTP POST. So you can't do much with that in VB6 except write code to do a POST in the right format. This is pretty well documented, however it is also not very useful so few people write any code for it.

    What happens with a file posted to a Web server is up to the Web server and server-side CGI script, etc. that received it.

    Very few Web servers accept HTTP PUT requests out of the blue, which is what you seem to be asking for.

  15. #15
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    The point is that there is no such thing as "an HTTP server" any more than a "TCP server."

    Of course there are HTTP servers as well as FTP servers. There are also SMTP severs and I'm sure that there are those that refer to it as a Mail servers? It doesn't really matter.

    I think the term Web Server refers to an application (or a computer itself) that takes care of the entire Web site installation and all the web spaces that are usually refered to as Web sites.

    All that matters is that you understand what HTTP and FTP is.

    The term HTTP server, for example, refers to an application (or even a computer) that processes the HTTP protocol language.
    The term FTP server refers to an application (or a computer) that processes the FTP protocol language.

    These two applications usually run on a Web Server (if Web server is a machine) or are running on their own if they are applications alongside the Web server application.

    Apache is a good example of an HTTP server and it is an application. As a matter of fact, my web site is hosted on a computer that has a funny name but it runs a Linux OS and on that same computer they run the Apache HTTP server.

    The OP probably wants something he can use in a VB program and maybe even as simple as possible. So posting any code that offers any help, like what I asked for, can benefit the OP and others as well. However, if you do not know yourself then of course you would have no code example to post.
    Last edited by jmsrickland; May 11th, 2011 at 05:38 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Transfer file to Remote Server

    as the op has used http uploading before, one must assume his server is set up for it
    i assumed that the server was not on LAN as it was described as remote
    as we have no details on what is set up on that server, we can not really offer any code samples

    even for web servers with file upload pages, i have never successfully automated the procedure
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Transfer file to Remote Server

    Sorry for the late reply. The server is not on LAN it is via net with static IP, from what i have done before i just create a virtual directory on IIS and then use HTTP Post and HTTP Get if im not mistaken. It works in .net but i haven't try it in vb6. currently im working on FTP put ang get.

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transfer file to Remote Server

    Quote Originally Posted by rothj0hn View Post
    Sorry for the late reply. The server is not on LAN it is via net with static IP, from what i have done before i just create a virtual directory on IIS and then use HTTP Post and HTTP Get if im not mistaken. It works in .net but i haven't try it in vb6. currently im working on FTP put ang get.
    If you have your "server guy" set up IIS with the WebDAV Extension from Microsoft that I linked above your problems are over.

    I'm not sure why anyone would want to make things any harder than they need to be. WebDAV is firewall-friendly and does not have to exchange logons in plain text over the Internet since you can use SSL (HTTPS). These are both problems with FTP.

    The IIS site covers the process in detail at Installing and Configuring WebDAV on IIS 7.


    Once this is in place you or your program can use the client redirector (which comes in Windows already) to map the WebDAV share to a drive letter and use it just like a file server. Uploading is done by simply using file copy statements.


    I don't know of any Web server that will accept POST requests to blindly transfer files. POSTs are supposed to be handled by an application, most often one accepting HTML Form input.

  19. #19
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    Quote Originally Posted by rothj0hn View Post
    Sorry for the late reply. The server is not on LAN it is via net with static IP, from what i have done before i just create a virtual directory on IIS and then use HTTP Post and HTTP Get if im not mistaken. It works in .net but i haven't try it in vb6. currently im working on FTP put ang get.
    HTTP POST and HTTP GET are not used to transfer files; at least not in the sense that you want to do so. The GET method is used for the client to get some file (like an HTML document, an image, etc) and the server returns this file in the contents of a Web page but there are cases when a Save As box popsup and allows you to save the data in the file. It's probably due to the way the GET was issued. The POST is used to send data to the server which is in the entity-body section of the client's request. This data is then sent on to the proper handlers (like a CGI script handler). If there is no such handler then I'm not sure what happens to the data; maybe it is just echoed back to you, I don't really know. However, POST is not used to send a file to the server like what I think you want to do.

    I'm not sure what you mean by saying it works in .net. HTTP has nothing to do with your version of VB (VB6 or VB.Net). It is a protocol used on the Internet by Web Servers (and more percisley by an HTTP Server) and it has a defined fixed set of protocol commands (or methods, if you like) and none of these commands can be used to send a file to a remote computer. Here I am talking about HTTP as it is used in the normal sense.
    Last edited by jmsrickland; May 12th, 2011 at 02:08 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Transfer file to Remote Server

    @dilettante, does it transfer file faster than FTP? sometimes i cant transfer file, then i ping the server, sometimes i got a request time out. does it affect the file transfer?

  21. #21
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Transfer file to Remote Server

    Quote Originally Posted by rothj0hn View Post
    @dilettante, does it transfer file faster than FTP?
    No, why would you expect it to be faster?
    Quote Originally Posted by rothj0hn View Post
    sometimes i cant transfer file, then i ping the server, sometimes i got a request time out. does it affect the file transfer?
    Well it does help to have a reliable network between you and the server.

    These seem like odd questions. There is no magic.

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Transfer file to Remote Server

    oic.. my FTP transfer is working now, i just thought using webdav is faster cause it only use filecopy commands.

    I have another question, now than i can already send and received file via ftp using put and get. how can i delete file on the server? i need to delete all files that already been get from server.

    thanks

  23. #23
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    Use commands delete and mdelete. These are not real FTP commands but neither are put and get. Whatever FTP shell or wrapper you are using if it accepts put and get then it should accept delete and mdelete.

    Usage: delete "path_to_folder/file"


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Transfer file to Remote Server

    Can i change the path on where to put all transfered file. currently it just go to the default path used by the ftp.

    vb Code:
    1. inetFTP.Execute , "Put " & _
    2.         gstExport & "\" & sFileName & " " & sFileName

    if i make it "C:\Test\" & sFilename then it will result to an error. something like Error: 123 "the filename, directory name, or volume label syntax is incorrect.

  25. #25
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    I don't know what is in sFilename but it has to be the entire path within quotes. Like this:


    Dim LocalFileName As String
    Dim RemoteFileName As String

    LocalFileName = "c:\Test\MyFile.txt"
    RemoteFileName = "www.somewebsite.com/subfolder/MyFile.txt"

    inet.Execute , "Put " & LocalFileName & " " & RemoteFileName

    This is the way it works on my computer and it works everytime I use it

    Some systems might require it this way:

    inet.Execute , "Put " & Chr$(34) & LocalPath & Chr$(34) & " " & Chr$(34) & RemotePath & Chr(34)

    EDIT:

    I posted an incorrect statement.

    INCORRECT RemoteFileName = "www.somewebsite.com/subfolder/MyFile.txt"
    CORRECT RemoteFileName = "/subfolder/MyFile.txt"
    Last edited by jmsrickland; May 17th, 2011 at 11:43 AM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    398

    Re: Transfer file to Remote Server

    im using an ftp site.

    vb Code:
    1. RemoteFileName = "ftp://121.1.60.150/C:/Test/"

    is this correct?

  27. #27
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Transfer file to Remote Server

    I'm not sure if the site (and/or API) allows that type of format using 121.1.60.150. I really doubt it. I think you need to use a name instead of the IP but don't quote me on that one..

    This is how I do it if I am using Inet. However, I usually do not use Inet; I use real FTP protocol to connect to my website. Note the quote marks Chr(34) on both sides of the paths. The problem with using Inet is that it will work for one site but fail on another.

    If your remote site is set up to do real FTP protocol then the below should work. Inet is a wrapper for the real FTP commands so as to make it easier for the programmer but I have found it is not as efficient and/or dependable as using a real FTP protocol connection.

    Code:
      '
      '
     LocalPath = Chr(34) & App.Path & "\myfile.txt" & Chr(34)
    
     '
     ' Only the path/filename is required; not the entire remote site.
     ' 
     RemotePath = Chr(34) & "/docs/today/myfile.txt" & Chr(34)
     
     inet.AccessType = icDirect
     inet.Protocol = icFTP
       
     inet.UserName = "username"
     inet.Password = "pass"
    
     '
     ' Some sites might require ftp instead of www. My website does
     ' not allow ftp.mywebsite.com
     ' 
     inet.RemoteHost = "www.mywebsite.com"
     
     inet.Execute inet.URL, "PUT " & LocalPath & " " & RemotePath
      '
      ' or optionally.....inet.Execute , "PUT " & LocalPath & " " & RemotePath
      '
    Last edited by jmsrickland; May 17th, 2011 at 12:30 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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