Anyone good with VB...? I'm stumped. It's
Dim localFile As String = "F:\Documents and Settings\User\My Documents\Downloads\Program\changes.txt"
Dim direct As String = "F:\Documents and Settings\User\My Documents\Downloads\Program"
Const remoteFile As String = "/changes.txt"
Const host As String = "A web host"
Const username As String = "MY USER NAME"
Const password As String = "MY PASS"
If My.Computer.FileSystem.DirectoryExists(direct) Then
System.IO.Directory.Delete(direct, True)
End If
System.IO.Directory.CreateDirectory(direct)
Dim URI As String = host & remoteFile
Dim ftp As System.Net.FtpWebRequest = _
CType(System.Net.WebRequest.Create(URI), System.Net.FtpWebRequest)
'2. Set credentials
ftp.Credentials = New _
System.Net.NetworkCredential(username, password)
'3. Settings and action
ftp.KeepAlive = False
'we want a binary transfer, not textual data
ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectory
Dim response As FtpWebResponse = CType(ftp.GetResponse(), FtpWebResponse)
Dim reader As New StreamReader(response.GetResponseStream())
Dim files() As String = reader.ReadToEnd().Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
response.Close()
For Each currentFile As String In files
Dim theWebClient As New WebClient()
theWebClient.Credentials = ftp.Credentials
theWebClient.DownloadFile(host & "/" & currentFile, direct & "\" & currentFile)
NextIt's supposed to download all of the files in my web host to the Program folder, but it doesn't owrk. No error, though...
Offline
Offline
SeptimusHeap wrote:
recycle49 wrote:
Eh me can not help you with dis
Then why'd you post...
First of all what are you running and what do you need to fix?
Offline
recycle49 wrote:
SeptimusHeap wrote:
recycle49 wrote:
Eh me can not help you with dis
Then why'd you post...
First of all what are you running and what do you need to fix?
Read the OP.
Offline
I got some sort of error in this part:
theWebClient.DownloadFile(host & "/" & currentFile, direct & "\" & currentFile)
But I think this part is wrong, too:
Dim files() As String = reader.ReadToEnd().Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)Offline
I made something like this which my program checks for updates. I can't remember the code but you don't need a password or username if you can download it without it.
Now I remember it was my scratch screensaver.
Search for "VB.net downloading files"
My site Offline
But it's not just supposed to download files. It's supposed to clear a directory by deleting and remaking it, then it finds all of the files on the pass-protected FTP server, and then it downloads ALL the files into the directory.
Offline
SeptimusHeap wrote:
Anyone good with VB...? I'm stumped. It's
Code:
Dim localFile As String = "F:\Documents and Settings\User\My Documents\Downloads\Program\changes.txt" Dim direct As String = "F:\Documents and Settings\User\My Documents\Downloads\Program" Const remoteFile As String = "/changes.txt" Const host As String = "A web host" Const username As String = "MY USER NAME" Const password As String = "MY PASS" If My.Computer.FileSystem.DirectoryExists(direct) Then System.IO.Directory.Delete(direct, True) End If System.IO.Directory.CreateDirectory(direct) Dim URI As String = host & remoteFile Dim ftp As System.Net.FtpWebRequest = _ CType(System.Net.WebRequest.Create(URI), System.Net.FtpWebRequest) '2. Set credentials ftp.Credentials = New _ System.Net.NetworkCredential(username, password) '3. Settings and action ftp.KeepAlive = False 'we want a binary transfer, not textual data ftp.Method = System.Net.WebRequestMethods.Ftp.ListDirectory Dim response As FtpWebResponse = CType(ftp.GetResponse(), FtpWebResponse) Dim reader As New StreamReader(response.GetResponseStream()) Dim files() As String = reader.ReadToEnd().Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) response.Close() For Each currentFile As String In files Dim theWebClient As New WebClient() theWebClient.Credentials = ftp.Credentials theWebClient.DownloadFile(host & "/" & currentFile, direct & "\" & currentFile) NextIt's supposed to download all of the files in my web host to the Program folder, but it doesn't owrk. No error, though...
I'm good with basic VBS, but not VB.
Offline
SeptimusHeap wrote:
But it's not just supposed to download files. It's supposed to clear a directory by deleting and remaking it, then it finds all of the files on the pass-protected FTP server, and then it downloads ALL the files into the directory.
Here's what I would do.
- Make a Program that downloads the new files to a file in the startup directory.
- The program then deletes or moves all old files (Move it for backup) (Don't delete the new files or the program)
- Program then copy's new files to the old location.
- Program then deletes files in the new folder
My program which updates:
Checks a text file on the net.
If file is different from current version it downloads the next installer.
It then runs the installer and shuts itself down for deletion.
The user then chooses the install settings.
My site Offline
what-the wrote:
SeptimusHeap wrote:
But it's not just supposed to download files. It's supposed to clear a directory by deleting and remaking it, then it finds all of the files on the pass-protected FTP server, and then it downloads ALL the files into the directory.
Here's what I would do.
- Make a Program that downloads the new files to a file in the startup directory.
- The program then deletes or moves all old files (Move it for backup) (Don't delete the new files or the program)
- Program then copy's new files to the old location.
- Program then deletes files in the new folder
My program which updates:
Checks a text file on the net.
If file is different from current version it downloads the next installer.
It then runs the installer and shuts itself down for deletion.
The user then chooses the install settings.
But I want it to download ALL the files in the FTp directory, and It isn't getting the contents right.
Offline
what-the wrote:
SeptimusHeap wrote:
But it's not just supposed to download files. It's supposed to clear a directory by deleting and remaking it, then it finds all of the files on the pass-protected FTP server, and then it downloads ALL the files into the directory.
Here's what I would do.
- Make a Program that downloads the new files to a file in the startup directory.
- The program then deletes or moves all old files (Move it for backup) (Don't delete the new files or the program)
- Program then copy's new files to the old location.
- Program then deletes files in the new folder
My program which updates:
Checks a text file on the net.
If file is different from current version it downloads the next installer.
It then runs the installer and shuts itself down for deletion.
The user then chooses the install settings.
But I want it to download ALL the files in the FTp directory, and It isn't getting the contents right.
Offline