CISA FotoGallery

Statistiche

Tot. visite contenuti : 928360
Home Articoli tecnici Access & Web Pubblicare un file in FTP con winInet

Pubblicare un file in FTP con winInet

Private Const ERROR_SUCCESS As Long = 0
Private Const INTERNET_OPEN_TYPE_PRECONFIG As Long = 0
Private Const INTERNET_SERVICE_FTP As Long = 1
Private Const INTERNET_FLAG_TRANSFER_BINARY As Long = 2
Private Const INTERNET_DEFAULT_FTP_PORT As Long = 21

Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" (ByVal lpszAgent As String, ByVal dwAccessType As Long,
ByVal lpszProxy As String, ByVal lpszProxyBypass As String, ByVal dwFlags As
Long) As Long

Private Declare Function InternetConnect Lib "wininet.dll" Alias
"InternetConnectA" (ByVal hInternetSession As Long, ByVal lpszServerName As
String, ByVal nServerPort As Integer, ByVal lpszUserName As String, ByVal
lpszPassword As String, ByVal dwService As Long, ByVal dwFlags As Long,
ByVal dwContext As Long) As Long

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet
As Long) As Boolean

Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA"
(ByVal hFTPSession As Long, ByVal lpszLocalFile As String, ByVal
lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long)
As Boolean

Public Function FTP(Server As String, UserName As String, Password As
String, LocalFile As String, RemoteFile As String) As Boolean
Dim hInternet As Long
Dim hFTPSession As Long
Dim bRet As Long

hInternet = InternetOpen(Application.Name, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)

hFTPSession = InternetConnect(hInternet, Server,
INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, 0, 0)

bRet = FtpPutFile(hFTPSession, LocalFile, RemoteFile,
INTERNET_FLAG_TRANSFER_BINARY, 0)

bRet = InternetCloseHandle(hFTPSession)

bRet = InternetCloseHandle(hInternet)

FTP = True

End Function