Télécharger et envoyer des fichiers sur un ftp en vbs
masterspirits
Messages postés1Date d'inscriptionjeudi 13 mars 2003StatutMembreDernière intervention 3 juin 2003
-
3 juin 2003 à 21:04
Sven666
Messages postés13Date d'inscriptionsamedi 1 mai 2004StatutMembreDernière intervention13 mai 2010
-
14 juil. 2005 à 14:39
Salut tlm. Je débute un peu en vbs, j'ai un ftp et j'aimerais pouvoir télécharger et uploader des fichiers dessus depuis un poste distant via le visual basic script.
Aussi si quelqu'un pouvait m'aider en me donnant la fonction et les syntaxes me permettant une telle manoeuvre de manière discrète et automatique sans intervention de l'utilisateur.Ce n'est pas spécialement urgent mais c'est dans le cadre d'un stage en entreprise et si c'est difficilement réalisable en VBS.Merci de me communiquer le langage, ses fonctions et syntaxes, qui me permettrai d'accomplir cette tâche plus facilement.
Merci d'avance 8-)
Sven666
Messages postés13Date d'inscriptionsamedi 1 mai 2004StatutMembreDernière intervention13 mai 2010 14 juil. 2005 à 14:39
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const INTERNET_DEFAULT_FTP_PORT = 21 ' default for FTP servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000 ' used for FTP connections
Const INTERNET_OPEN_TYPE_PRECONFIG = 0 ' use registry configuration
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
Private Sub Command1_Click()
Me.LancementProcedure
End Sub
Public Sub LancementProcedure()
Dim Source As String, Destination As String
Dim gg As String
'ne pas supprimer les double "//"
'PS: ne fonctionne que pour les fichiers se trouvant dans la racine du site
Source = "http://steevmau.free.fr//donnees.ini"
Destination = App.Path & "\donnees.ini"
DownloadFile Source, Destination
End Sub
Public Function DownloadFile(ByVal sURL As String, ByVal sLocalFile As String) As Boolean
Dim lngRetVal As LongDownloadFile URLDownloadToFile(0&, sURL, sLocalFile, 0&, 0&) ERROR_SUCCESS
End Function
Private Sub Command2_Click()
Dim hopen As Long, hConnection As Long, toto As String
hopen = InternetOpen("SERVEUR ftp", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hConnection = InternetConnect(hopen, "ftpperso.free.fr", INTERNET_DEFAULT_FTP_PORT, "nom_user", "mot_de_passe", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
toto = String(260, 0)
FtpSetCurrentDirectory hConnection, "/data/ONYX/GEAE/OUT/INFO3SNS"
FtpGetCurrentDirectory hConnection, toto, Len(toto)
' fichier sur local nom fichier sur FTP
FtpPutFile hConnection, App.Path & "\donnees.ini", "/donnees.ini", FTP_TRANSFER_TYPE_ASCII, 0
'close the FTP connection
InternetCloseHandle hConnection
End Sub