Hi, I am struggling to resolve this, and may not be resolvable because of firewall security?
I trigger this FTP code to upload a PDF file which has just been generated to my website.
If I deactivate my virus protection software, works fine. If not, is blocked.
Any suggestions whether there is a way around this with coding?
Thanks!
I trigger this FTP code to upload a PDF file which has just been generated to my website.
If I deactivate my virus protection software, works fine. If not, is blocked.
Any suggestions whether there is a way around this with coding?
Thanks!
Code:
Option Compare Database
Private Const FTP_TRANSFER_TYPE_UNKNOWN As Long = 0
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Private Declare PtrSafe Function InternetOpenA Lib "wininet.dll" ( _
ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) As LongPtr
Private Declare PtrSafe Function InternetConnectA Lib "wininet.dll" ( _
ByVal hInternetSession As LongPtr, _
ByVal sServerName As String, _
ByVal nServerPort As Long, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Long, _
ByVal lFlags As Long, _
ByVal lcontext As Long) As LongPtr
Private Declare PtrSafe Function FtpGetFileA Lib "wininet.dll" ( _
ByVal hconnect As LongPtr, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As LongPtr
Private Declare PtrSafe Function FtpPutFileA _
Lib "wininet.dll" _
_
(ByVal hFtpSession As LongPtr, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As LongPtr
Private Declare PtrSafe Function InternetCloseHandle Lib "wininet" ( _
ByVal hInet As LongPtr) As LongPtr
'WORKING IF ALLOWED VIA FIREWALL!!!
Sub FtpDownload(ByVal strRemoteFile As String, ByVal strLocalFile As String, ByVal strHost As String, ByVal lngPort As Long, ByVal strUser As String, ByVal strPass As String)
Dim hOpen As LongPtr
Dim hConn As LongPtr
hOpen = InternetOpenA("FTPGET", 1, vbNullString, vbNullString, 1)
hConn = InternetConnectA(hOpen, strHost, lngPort, strUser, strPass, 1, 0, 2)
If FtpGetFileA(hConn, strRemoteFile, strLocalFile, 1, 0, FTP_TRANSFER_TYPE_UNKNOWN Or INTERNET_FLAG_RELOAD, 0) Then
Debug.Print "Success"
Else
Debug.Print "Fail"
End If
'Close connections
InternetCloseHandle hConn
InternetCloseHandle hOpen
End Sub
Sub FtpUpload(ByVal strLocalFile As String, ByVal strRemoteFile As String, ByVal strHost As String, ByVal lngPort As Long, ByVal strUser As String, ByVal strPass As String)
Dim hOpen As LongPtr
Dim hConn As LongPtr
hOpen = InternetOpenA("FTPGET", 1, vbNullString, vbNullString, 1)
hConn = InternetConnectA(hOpen, strHost, lngPort, strUser, strPass, 1, 0, 2)
If FtpPutFileA(hConn, strLocalFile, strRemoteFile, FTP_TRANSFER_TYPE_UNKNOWN Or INTERNET_FLAG_RELOAD, 0) Then
Debug.Print "Success"
Else
Debug.Print "Fail"
MsgBox "Is Antivirus Firewall blocking this code?"
End If
'Close connections
InternetCloseHandle hConn
InternetCloseHandle hOpen
End Sub
Function Upload_PDF(SaveDir As String, pdfname As String)
FtpUpload SaveDir & pdfname, "/xxxx.com/public_html/Reports/" & pdfname, _
"11.111.11.111", 21, "xxxx@xxxx.com", "xxxxxx"
End Function