Hallo,
ich versuche eine Datei auf einen FTP-Server zu laden.
Als Rückgabewert für die Function FtpPutFile bekomme ich immer False, und die Datei wird nicht hoch geladen.
Ich weis auch nicht genau ob ich die Verbindung gleich wider schliessen kann, deswegen warte ich 10s.
Für hOpen und hConnection bekomme ich recht lange Zahlenketten.
Also denke und hoffe ich mal, dass eine Verbindung zu Stande kommt.
Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet 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 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 FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" ( _
ByVal hConnect As
Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, _
ByVal fFailIfExists As
Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef _
dwContext As Long) As
Boolean
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
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Const PassiveConnection As Boolean = True
Const FTPAddress = "ftp://ftp.xxxxx.de"
Const UserName = "xxx"
Const Password = "xxx"
Const ProgName = "MeinProg"
Public Sub PutFileToServer(ByVal sLocalFile As String, ByVal sFtpFileName _
As String)
Dim hConnection As Long, hOpen As Long
sLocalFile = "C:\Test\Testfile.xls" : sFtpFileName = "Testfile.xls"
Dim sProxy As String = "10.xx.xxx.150"
hOpen = InternetOpen(ProgName, INTERNET_OPEN_TYPE_PROXY, sProxy , _
vbNullString, 0)
hConnection = InternetConnect(hOpen, FTPAddress, _
INTERNET_DEFAULT_FTP_PORT, _
UserName,Password, INTERNET_SERVICE_FTP, IIf( _
PassiveConnection, _
INTERNET_FLAG_PASSIVE, 0), 0)
Dim blnSendet = FtpPutFile(hConnection, sLocalFile, sFtpFileName, 2, 0)
Do Until blnSendet
If Timeout > 9 Then Exit Do
Sleep(1000)
Timeout += 2
Loop
InternetCloseHandle(hConnection)
InternetCloseHandle(hOpen)
hConnection = Nothing
hOpen = Nothing
If blnSendet Then
MsgBox("Gesendet")
Else
MsgBox("Nicht gesendet")
End If
End Sub Ich wäre sehr dankbar wenn jemand weiter weis.
Gruß Chris |