|
-
Aug 22nd, 2007, 03:20 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Aug 22nd, 2007, 04:19 AM
#2
Hyperactive Member
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:
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create("ftp://192.168.0.1/test.zip"), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("Username", "passxxx")
clsRequest.UseBinary = True
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
clsRequest.UsePassive = False
' read in file...
Dim bFile(5000000 - 1) As Byte
Dim strmFile As FileStream = File.OpenRead("d:\test.zip")
' upload file...
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
For y = 1 To x
strmFile.Read(bFile, 0, 200000)
clsStream.Write(bFile, 0, 200000)
Application.DoEvents()
Next
''write end of file here
Dim abyBuffer2(strmFile.Length - x * 200000 - 1) As Byte
strmFile.Read(bFile, 0, strmFile.Length)
clsStream.Write(bFile, 0, strmFile.Length)
clsStream.Close()
clsStream.Dispose()
System.GC.Collect()
Last edited by PENNYSTOCK; Aug 22nd, 2007 at 04:24 AM.
Visual Studio .NET 2005/.NET Framework 2.0
-
Aug 22nd, 2007, 04:33 AM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|