Bonjour,
En vu de la fructueuse aide que j'ai reçu lors de mon premier post, je reviens vers votre excellent forum dans l'espoir de completer ma macro VB.
J'essaie de developper une macro pour telecharger des fichiers CSV à partir d'un serveur FTP.
Ma première form est une simple interface de contrôle username/password.
Ma deuxième form contient les credentiels à renseigner pour le serveur FTP, mlheureusement, cette dernière ne s'ouvre pas au bon format (taille), et ne contient aucun bouton contrairement à son design.
Le code de ma deuxième form :
Et voici l'arborescence de mon projet : Lien supprimé
J'ai essayé de la renomer Form2 mais ça ne marche pas autant que MainForm.
Merci de bien vouloir m'eclairer ^^
Cordialement,
En vu de la fructueuse aide que j'ai reçu lors de mon premier post, je reviens vers votre excellent forum dans l'espoir de completer ma macro VB.
J'essaie de developper une macro pour telecharger des fichiers CSV à partir d'un serveur FTP.
Ma première form est une simple interface de contrôle username/password.
Ma deuxième form contient les credentiels à renseigner pour le serveur FTP, mlheureusement, cette dernière ne s'ouvre pas au bon format (taille), et ne contient aucun bouton contrairement à son design.
VB:
Public Class Form1
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs)
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "User" And TextBox2.Text = "User" Then
MainForm.Show()
Else
MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid")
End If
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
End Sub
End Class
Le code de ma deuxième form :
VB:
Imports System.Net
Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Control.CheckForIllegalCrossThreadCalls = False
End Sub
Private Sub btnBrowseSave_Click(sender As Object, e As EventArgs) Handles btnBrowseSave.Click
Dim newFolder As New FolderBrowserDialog
If newFolder.ShowDialog = Windows.Forms.DialogResult.OK Then
txtSavePath.Text = newFolder.SelectedPath
End If
End Sub
Private Sub btnDownload_Click(sender As Object, e As EventArgs) Handles btnDownload.Click
bWorker.RunWorkerAsync()
End Sub
Private Sub bWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles bWorker.DoWork
Dim buffer(1023) As Byte
Dim bytesIN As Integer
Dim totalBytesIn As Integer
Dim output As IO.Stream
Dim flLength As Integer
Try
Dim FTPRequest As FtpWebRequest = DirectCast(WebRequest.Create(txtFilePath.Text), FtpWebRequest)
FTPRequest.Credentials = New NetworkCredential(txtFTPUsername.Text, txtFTPassword.Text)
FTPRequest.Method = Net.WebRequestMethods.Ftp.GetFileSize
flLength = CInt(FTPRequest.GetResponse.ContentLength)
lblFileSize.Text = flLength & " bytes "
Catch ex As Exception
End Try
Try
Dim FTPRequest As FtpWebRequest = DirectCast(WebRequest.Create(txtFilePath.Text), FtpWebRequest)
FTPRequest.Credentials = New NetworkCredential(txtFTPUsername.Text, txtFTPassword.Text)
FTPRequest.Method = WebRequestMethods.Ftp.DownloadFile
Dim stream As System.IO.Stream = FTPRequest.GetResponse.GetResponseStream
Dim OutputFilePath As String = txtSavePath.Text & "\" & IO.Path.GetFileName(txtFilePath.Text)
output = System.IO.File.Create(OutputFilePath)
bytesIN = 1
Do Until bytesIN < 1
bytesIN = stream.Read(buffer, 0, 1024)
If bytesIN > 0 Then
output.Write(buffer, 0, bytesIN)
totalBytesIn += bytesIN
lblDownloadedBytes.Text = totalBytesIn.ToString & "bytes"
If flLength > 0 Then
Dim perc As Integer = (totalBytesIn / flLength) * 100
bWorker.ReportProgress(perc)
End If
End If
Loop
output.Close()
stream.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub bWorker_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles bWorker.ProgressChanged
pBar.Value = e.ProgressPercentage
lblPercent.Text = e.ProgressPercentage.ToString & "%"
End Sub
Private Sub bWorker_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bWorker.RunWorkerCompleted
MsgBox("Download Complete!")
End Sub
Private Sub Label8_Click(sender As Object, e As EventArgs) Handles Label8.Click
End Sub
Private Sub Label9_Click(sender As Object, e As EventArgs) Handles lblPercent.Click
End Sub
End Class
Et voici l'arborescence de mon projet : Lien supprimé
J'ai essayé de la renomer Form2 mais ça ne marche pas autant que MainForm.
Merci de bien vouloir m'eclairer ^^
Cordialement,