Hi all,
I am using the following macro to copy a file C:\a.txt to an ftp server .
I have added “Microsoft Internet controls” reference.
I am getting Runtime error 5:Invalid procedure call or argument.
Any idea how to add wininet.dll to references? ( i tried doing a browse and manually adding wininet.dll but it says “Cant add reference to the specified file” .
Any help is appreciated.
Or If the ftp can be done in a better way…That would help a lot.
Thanks in Advance,
Ashwin N
Private Declare Function InternetOpen _
Lib “wininet.dll” Alias “InternetOpenA” ( _
ByVal sAgent As String, _
ByVal nAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal nFlags As Long) As Long
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 nService As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Private Declare Function FtpPutFile _
Lib “wininet.dll” Alias “FtpPutFileA” ( _
ByVal hFtpSession As Long, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Private Declare Function InternetCloseHandle _
Lib “wininet.dll” (ByVal hInet As Long) As Integer
Private Declare Function GetLastError Lib “coredll” () As Long
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_SERVICE_GOPHER = 2
Private Const INTERNET_SERVICE_HTTP = 3
Public Sub FTPSend()
Dim hINetSession As Long, hSession As Long, xfrtype As Integer
hINetSession = InternetOpen("MyFTPClient", 0, vbNullString, vbNullString, 0)
hSession = InternetConnect(hINetSession, "(ftp server address)", _
"21", "(username)", "(password)", INTERNET_SERVICE_FTP, 0, 0)
With Err
If .Number = 20 And .Description = “Cannot find the variable by its name.” Then
blnVariablePresent = False
Else
.Raise .Number, .Source, .Description, .HelpFile, .HelpContext
End If
End With
Call InternetCloseHandle(hSession)
Call InternetCloseHandle(hINetSession)
End Sub
ashwin_n84 (BOB member since 2006-04-25)