Results 1 to 3 of 3

Thread: [2005] Upload/Download .txt File From FTP Server.

  1. #1

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    [2005] Upload/Download .txt File From FTP Server.

    I need some code for VB 2005 that will allow the user to automatically download a .txt file from a FTP server and put it in the directory: C:\MYAPPNAME\Data\txtfile.txt.

    Also I would like some code that allows the user to automatically upload the same txtfile to the same FTP Server from the C:\MYAPPNAME\Data\txtfile.txt directory.

    Thanks in advance. - (If you only know code for one thing then please post it. Someone else might have the other bit )

    Also would it connect using http:// or ftp:// ???

    Also my FTP Server may have(depending on what server I use) username and password protection, so just put 'username' and 'password' in the places where I would need to write them.

    Thanks in advance (again)

    -----
    knxrb
    Last edited by knxrb; Aug 22nd, 2007 at 03:36 AM.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Re: [2005] Upload/Download .txt File From FTP Server.

    There is the this for uploading. Look up these classes for downloading help.

    My.Computer.Network.UploadFile("C:\logo.gif", "ftp://192.168.0.252/ICA/logo.gif", "adminuser", "passxxx")

    or this

    VB Code:
    1. Dim clsRequest As System.Net.FtpWebRequest = _
    2.             DirectCast(System.Net.WebRequest.Create("ftp://192.168.0.1/test.zip"), System.Net.FtpWebRequest)
    3.         clsRequest.Credentials = New System.Net.NetworkCredential("Username", "passxxx")
    4.         clsRequest.UseBinary = True
    5.         clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
    6.         clsRequest.UsePassive = False
    7.         ' read in file...
    8.         Dim bFile(5000000 - 1) As Byte
    9.         Dim strmFile As FileStream = File.OpenRead("d:\test.zip")
    10.  
    11.         ' upload file...
    12.         Dim clsStream As System.IO.Stream = _
    13.             clsRequest.GetRequestStream()
    14.  
    15.         For y = 1 To x
    16.             strmFile.Read(bFile, 0, 200000)
    17.             clsStream.Write(bFile, 0, 200000)
    18.             Application.DoEvents()
    19.         Next
    20.  
    21. ''write end of file here
    22.         Dim abyBuffer2(strmFile.Length - x * 200000 - 1) As Byte
    23.         strmFile.Read(bFile, 0, strmFile.Length)
    24.         clsStream.Write(bFile, 0, strmFile.Length)
    25.  
    26.         clsStream.Close()
    27.         clsStream.Dispose()
    28.         System.GC.Collect()
    Last edited by PENNYSTOCK; Aug 22nd, 2007 at 04:24 AM.
    Visual Studio .NET 2005/.NET Framework 2.0

  3. #3

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Upload/Download .txt File From FTP Server.

    Thanks, will try the code soon

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