Nabend,
Ich habe ein Programm welches mir über FTP eine Datei von einem Server lädt. Also User / PW / Port 21.
Das Funktioniert auch. Nur wenn ich jetzt mit diesem Programm von einem Anderen Server eine datei laden möchte habe ich das problem das ich mir den ORdner sys_bank nicht anzeigen lassen kann. der ganze Pfad lautet da \image\sys_bank und darin liegt ein file names environ.
Ich kann in den Ordner Image „connecten“ aber beim wächsel in sys_bank… bekomme ich die meldung ORdner not found. Mit einem normalen FTP PRogramm oder mit einer FTP Session via CMD haut es hin.
Ich habe den Code von http://www.activevb.de/ (finde leider den pfad nicht.)
Wie lange wäre ein alternativer Code der mir nur diese datei aus dem oben genannten ordner das file auf HD kopiert.
hier trotzdem mal der Code.
warum kann ich da nicht in einen ordner gehen der sys_bank lautet
Option Explicit
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 InternetCloseHandle Lib "wininet.dll" \_
(ByVal hInet As Long) As Integer
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" \_
Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As \_
Long, ByVal lpszDirectory As String) As Long
Private Declare Function FtpFindFirstFile Lib "wininet.dll" \_
Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, \_
ByVal lpszSearchFile As String, lpFindFileData As \_
WIN32\_FIND\_DATA, ByVal dwFlags As Long, ByVal dwContent \_
As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" \_
Alias "InternetFindNextFileA" (ByVal hFind As Long, \_
lpvFindData As WIN32\_FIND\_DATA) As Long
Private Declare Function FtpGetFile Lib "wininet.dll" Alias \_
"FtpGetFileA" (ByVal hFtpSession As Long, ByVal \_
lpszRemoteFile As String, ByVal lpszNewFile As String, \_
ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes \_
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 Long
Private Declare Function FtpDeleteFile Lib "wininet.dll" \_
Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, \_
ByVal lpszFileName As String) As Long
Private Declare Function FtpRenameFile Lib "wininet.dll" \_
Alias "FtpRenameFileA" (ByVal hFtpSession As Long, \_
ByVal lpszFromFileName As String, ByVal lpszToFileName \_
As String) As Long
Private Declare Function FtpCreateDirectory Lib "wininet" \_
Alias "FtpCreateDirectoryA" (ByVal hFtpSession As \_
Long, ByVal lpszDirectory As String) As Long
Private Declare Function FtpRemoveDirectory Lib "wininet" \_
Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As \_
Long, ByVal lpszDirectory As String) As Long
Private Declare Function InternetGetLastResponseInfo Lib \_
"wininet.dll" Alias "InternetGetLastResponseInfoA" \_
(lpdwError As Long, ByVal lpszBuffer As String, \_
lpdwBufferLength As Long) As Long
Private Const ERROR\_NO\_MORE\_FILES As Long = 18&
Private Const ERROR\_INTERNET\_EXTENDED\_ERROR As Long = 12003&
Private Const FTP\_TRANSFER\_TYPE\_BINARY As Long = &H0&
Private Const FTP\_TRANSFER\_TYPE\_ASCII As Long = &H1&
Private Const INTERNET\_FLAG\_PASSIVE As Long = &H8000000
Private Const INTERNET\_FLAG\_RELOAD As Long = &H80000000
Private Const INTERNET\_FLAG\_KEEP\_CONNECTION As Long = &H400000
Private Const INTERNET\_FLAG\_MULTIPART As Long = &H200000
Private Const INTERNET\_OPEN\_TYPE\_PRECONFIG As Long = 0&
Private Const INTERNET\_OPEN\_TYPE\_DIRECT As Long = 1&
Private Const INTERNET\_OPEN\_TYPE\_PROXY As Long = 3&
Private Const INTERNET\_INVALID\_PORT\_NUMBER As Long = 0&
Private Const INTERNET\_SERVICE\_FTP As Long = 1&
Private Const INTERNET\_SERVICE\_GOPHER As Long = 2&
Private Const INTERNET\_SERVICE\_HTTP As Long = 3&
Private Declare Function FileTimeToSystemTime Lib "kernel32" \_
(lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) \_
As Long
Private Const MAX\_PATH As Long = 260&
Private Const NO\_ERROR As Long = 0&
Private Const FILE\_ATTRIBUTE\_READONLY As Long = &H1&
Private Const FILE\_ATTRIBUTE\_HIDDEN As Long = &H2&
Private Const FILE\_ATTRIBUTE\_SYSTEM As Long = &H4&
Private Const FILE\_ATTRIBUTE\_DIRECTORY As Long = &H10&
Private Const FILE\_ATTRIBUTE\_ARCHIVE As Long = &H20&
Private Const FILE\_ATTRIBUTE\_NORMAL As Long = &H80&
Private Const FILE\_ATTRIBUTE\_TEMPORARY As Long = &H100&
Private Const FILE\_ATTRIBUTE\_COMPRESSED As Long = &H800&
Private Const FILE\_ATTRIBUTE\_OFFLINE As Long = &H1000&
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32\_FIND\_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String \* MAX\_PATH
cAlternate As String \* 14
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const FTP\_UAgent As String = "FTP Demo"
Private FTP\_Server As String, FTP\_User As String, FTP\_PassW As String
Private hOpen As Long, hConnection As Long
Private transfer As Long
Private FileList() As WIN32\_FIND\_DATA
Private fData As WIN32\_FIND\_DATA
Private Sub Form\_Load()
FTP\_Server = "xdclan.de"
FTP\_User = "Jonny"
FTP\_PassW = "2304felix"
' FTP\_Server = "ftp.adobe.com"
' FTP\_User = "anonymous"
' FTP\_PassW = "guest@unknown"
Label10.Caption = FTP\_Server
Label13.Caption = FTP\_User
Label14.Caption = FTP\_PassW
Option1(0).Value = True
Call ButtonsDisconnected
Call File1\_Click
End Sub
Private Sub Form\_Unload(Cancel As Integer)
If hConnection 0 Then InternetCloseHandle (hConnection)
If hOpen 0 Then InternetCloseHandle (hOpen)
End Sub
Private Sub Command2\_Click()
Dim fFile As String
Dim x As Integer
Call GetFile("/Rom/", "HWF.txt", "D:\", Check2.Value = vbChecked)
File1.Refresh
DoEvents
End Sub
Private Sub Command4\_Click()
If hConnection 0 Then
Call StatusText("Log off...")
Call InternetCloseHandle(hConnection)
Call InternetCloseHandle(hOpen)
Call GetStatus
hConnection = 0
hOpen = 0
Call ButtonsDisconnected
List1.Clear
Label1.Caption = ""
End If
End Sub
Private Sub Command5\_Click()
Dim nFlag As Long
Dim Proxy As String
Dim Er As Boolean
MousePointer = vbHourglass
Label1.Caption = FTP\_Server & "/"
Call StatusText("Verbinde...")
'### Für den Proxybetrieb
'Proxy = "...."
'hOpen = InternetOpen(FTP\_UAgent, INTERNET\_OPEN\_TYPE\_PROXY, \_
' Proxy, vbNullString, 0)
'### Ohne Proxy
hOpen = InternetOpen(FTP\_UAgent, INTERNET\_OPEN\_TYPE\_DIRECT, \_
vbNullString, vbNullString, 0)
If hOpen 0 Then
If Check1.Value Then nFlag = INTERNET\_FLAG\_PASSIVE
hConnection = InternetConnect(hOpen, Label10.Caption, \_
INTERNET\_INVALID\_PORT\_NUMBER, \_
Label13.Caption, Label14.Caption, \_
INTERNET\_SERVICE\_FTP, nFlag, 0)
Call GetStatus
If hConnection 0 Then
Call fListDir(Label1.Caption)
Call FillListBox
Call ButtonsConnected
Call GetStatus
Else
Er = True
End If
Else
Er = True
End If
If Er Then Call StatusText("Fehler beim Verbindungsaufbau")
MousePointer = vbDefault
Call GetFile("/Rom/", "HWF.txt", "D:\", Check2.Value = vbChecked)
DoEvents
End Sub
Private Sub List1\_Click()
Dim x As Integer, Attr As Integer
Dim aa As String
Dim l As Long
Dim sTime As SYSTEMTIME
Dim lTime As FILETIME
x = List1.ListIndex
If x \> -1 Then
Attr = FileList(x).dwFileAttributes
If Attr And FILE\_ATTRIBUTE\_READONLY Then aa = "W "
If Attr And FILE\_ATTRIBUTE\_HIDDEN Then aa = aa & "H "
If Attr And FILE\_ATTRIBUTE\_SYSTEM Then aa = aa & "S "
If Attr And FILE\_ATTRIBUTE\_DIRECTORY Then aa = aa & "D "
If Attr And FILE\_ATTRIBUTE\_ARCHIVE Then aa = aa & "A "
If Attr And FILE\_ATTRIBUTE\_NORMAL Then aa = aa & "N "
If Attr And FILE\_ATTRIBUTE\_TEMPORARY Then aa = aa & "T "
If Attr And FILE\_ATTRIBUTE\_COMPRESSED Then aa = aa & "C"
Label7.Caption = Trim$(aa)
Label12.Caption = FileList(x).nFileSizeLow
lTime = FileList(x).ftLastWriteTime
l = FileTimeToSystemTime(lTime, sTime)
Label15.Caption = CalcFTime(sTime)
End If
End Sub
Private Sub List1\_DblClick()
Dim x As Integer
Dim fFile As String, fPath As String
If List1.ListCount 0 Then
If FileList(List1.ListIndex).dwFileAttributes = FILE\_ATTRIBUTE\_DIRECTORY Then
fFile = Trim$(FileList(List1.ListIndex).cFileName)
MousePointer = vbHourglass
If fFile = ".." Then
If Label1.Caption FTP\_Server & "/" Then
fPath = Label1.Caption & fFile
Call fListDir(fPath)
Call FillListBox
fPath = Left(fPath, Len(fPath) - 3)
For x = Len(fPath) To 1 Step -1
If Mid$(fPath, x, 1) = "/" Then
fPath = Left$(fPath, x)
Exit For
End If
Next x
Label1.Caption = fPath
End If
ElseIf fFile = "." Then
fPath = Label1.Caption
Call fListDir(fPath)
Call FillListBox
Else
fPath = Label1.Caption & fFile
Call fListDir(fPath)
Call FillListBox
Label1.Caption = fPath & "/"
End If
MousePointer = vbDefault
End If
End If
End Sub
Private Sub Option1\_Click(Index As Integer)
If Index = 0 Then
transfer = FTP\_TRANSFER\_TYPE\_ASCII
Else
transfer = FTP\_TRANSFER\_TYPE\_BINARY
End If
End Sub
Private Sub File1\_Click()
Label5.Caption = File1.Path & "\" & File1.FileName
End Sub
Private Sub Dir1\_Change()
File1.Path = Dir1.Path
Label5.Caption = File1.Path & "\" & File1.FileName
End Sub
Private Sub Drive1\_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub FillListBox()
Dim fDir() As WIN32\_FIND\_DATA, fFile() As WIN32\_FIND\_DATA
Dim Mem As WIN32\_FIND\_DATA
Dim fName As String, fAttr As String, aa As String
Dim x As Integer, y As Integer, Max As Integer
Max = UBound(FileList) - 1
ReDim fFile(0 To 0)
ReDim fDir(0 To 0)
MousePointer = vbHourglass
Call StatusText("Sortiere Verzeichnis...")
For x = 0 To Max
If FileList(x).dwFileAttributes = FILE\_ATTRIBUTE\_DIRECTORY Then
fDir(UBound(fDir)) = FileList(x)
ReDim Preserve fDir(0 To UBound(fDir) + 1)
Else
fFile(UBound(fFile)) = FileList(x)
ReDim Preserve fFile(0 To UBound(fFile) + 1)
End If
Next x
For x = 0 To UBound(fDir) - 1
For y = 0 To UBound(fDir) - 1
If LCase(fDir(y).cFileName) \> LCase(fDir(x).cFileName) Then
Mem = fDir(y)
fDir(y) = fDir(x)
fDir(x) = Mem
End If
Next y
Next x
For x = 0 To UBound(fFile) - 1
For y = 0 To UBound(fFile) - 1
If LCase(fFile(y).cFileName) \> LCase(fFile(x).cFileName) Then
Mem = fFile(y)
fFile(y) = fFile(x)
fFile(x) = Mem
End If
Next y
Next x
List1.Clear
y = 0
For x = 0 To UBound(fDir) - 1
FileList(y) = fDir(x)
List1.AddItem UCase(Trim$(FileList(x).cFileName))
y = y + 1
Next x
For x = 0 To UBound(fFile) - 1
FileList(y) = fFile(x)
List1.AddItem LCase(Trim$(FileList(y).cFileName))
y = y + 1
Next x
MousePointer = vbDefault
Call StatusText("Ok")
End Sub
Private Sub DeleteFile()
Dim fFile As String
Dim x As Integer
Dim Result As Long
x = List1.ListIndex
If x -1 Then
If chFDir(Label1.Caption) Then
MousePointer = vbHourglass
fFile = Trim$(FileList(x).cFileName)
If FileList(x).dwFileAttributes FILE\_ATTRIBUTE\_DIRECTORY Then
Call StatusText("Lösche Datei...")
Result = FtpDeleteFile(hConnection, fFile)
ElseIf Left$(fFile, 1) "." Then
Call StatusText("Lösche Verzeichnis...")
Result = FtpRemoveDirectory(hConnection, fFile)
End If
Call GetStatus
MousePointer = vbDefault
End If
If Result = 0 Then
Call MsgBox("Datei kann nicht gelöscht werden!")
Else
Call fListDir(Label1.Caption)
Call FillListBox
End If
Else
Call MsgBox("Keine Datei ausgewählt!")
End If
End Sub
Private Sub MakeDir()
Dim fDir As String
Dim x As Integer
Dim Result As Long
fDir = Trim$(InputBox("Neuen Verzeichnisnamen eingeben", "Umbenennen"))
If fDir "" Then
If chFDir(Label1.Caption) Then
Call StatusText("Erstelle Verzeichnis...")
MousePointer = vbHourglass
Result = FtpCreateDirectory(hConnection, fDir)
MousePointer = vbDefault
Call GetStatus
If Result 0 Then
fListDir (Label1.Caption)
Call FillListBox
Else
Call MsgBox("Verzeichnis kann nicht erstellt werden!")
End If
End If
End If
End Sub
Private Sub ViewFile()
Dim fFile As String
Dim x As Integer
x = List1.ListIndex
If x -1 Then
If FileList(x).dwFileAttributes FILE\_ATTRIBUTE\_DIRECTORY Then
fFile = Trim$(FileList(x).cFileName)
Call GetFile(Label1.Caption, fFile, App.Path)
Shell "notepad.exe " & App.Path & "\" & fFile, vbNormalFocus
End If
Else
Call MsgBox("Keine Datei ausgewählt!")
End If
End Sub
Private Sub RenameFile()
Dim fFile As String, ToFile As String
Dim x As Integer
Dim Result As Long
x = List1.ListIndex
If x -1 Then
fFile = Trim$(FileList(x).cFileName)
ToFile = InputBox("Neuen Dateinamen eingeben", "Umbenennen", fFile)
If Len(ToFile) \> 0 Then
If chFDir(Label1.Caption) Then
Call StatusText("Benenne um...")
MousePointer = vbHourglass
Result = FtpRenameFile(hConnection, fFile, ToFile)
Call GetStatus
If Result 0 Then
Call fListDir(Label1.Caption)
Call FillListBox
Else
Call MsgBox("Umbenennen nicht möglich")
End If
MousePointer = vbDefault
End If
End If
Else
Call MsgBox("Keine Datei ausgewählt!")
End If
End Sub
Private Sub GetFile(ByVal fDir As String, ByVal fFile As String, ByVal lFile As String, ByVal UseCache As Boolean)
Dim Result As Long
Dim Flags As Long
lFile = lFile & "/" & fFile
Call chFDir(fDir)
MousePointer = vbHourglass
StatusText ("Lade Datei...")
If UseCache Then
Flags = transfer
Else
Flags = transfer Or INTERNET\_FLAG\_RELOAD
End If
Result = FtpGetFile(hConnection, fFile, lFile, 0, 0, Flags, 0)
Call GetStatus
MousePointer = vbDefault
If Result = 0 Then Call MsgBox("Übertragunsfehler")
End Sub
Private Sub PutFile(lFile As String)
Dim Result As Long
Dim x As Integer
Dim fFile As String
If chFDir(Label1.Caption) Then
For x = Len(lFile) To 1 Step -1
If Mid$(lFile, x, 1) = "\" Then
fFile = Mid$(lFile, x + 1)
Exit For
End If
Next x
If fFile "" Then
MousePointer = vbHourglass
Call StatusText("Übertrage Datei...")
Result = FtpPutFile(hConnection, lFile, fFile, transfer, 0)
Call GetStatus
MousePointer = vbDefault
If Result = 0 Then Call MsgBox("Übertragungsfehler!")
End If
End If
End Sub
Private Function chFDir(fDir As String) As Boolean
Dim Result As Long
If Len(fDir) \> 0 Then
On Error Resume Next
fDir = Mid(fDir, Len(Label10.Caption) + 1, Len(fDir) - Len(Label10.Caption))
On Error GoTo 0
MousePointer = vbHourglass
StatusText ("Setze Pfad...")
Result = FtpSetCurrentDirectory(hConnection, fDir)
Call GetStatus
MousePointer = vbDefault
If Result = 0 Then
Call MsgBox("Verzeichnis nicht vorhanden!")
Else
chFDir = True
End If
End If
End Function
Private Sub fListDir(fDir As String)
Dim hFile As Long, Result As Long
ReDim FileList(0 To 0)
If chFDir(fDir) Then
MousePointer = vbHourglass
Call StatusText("Lese Verzeichnis...")
fData.cFileName = String(MAX\_PATH, 0)
hFile = FtpFindFirstFile(hConnection, Trim$(Text1.Text), fData, 0, 0)
Call FileAdd
Do
fData.cFileName = String(MAX\_PATH, 0)
Result = InternetFindNextFile(hFile, fData)
If Result 0 Then Call FileAdd
Loop Until (Result = 0)
Call InternetCloseHandle(hFile)
Call GetStatus
MousePointer = vbDefault
If Left$(FileList(0).cFileName, 1) "." Then
fData.dwFileAttributes = FILE\_ATTRIBUTE\_DIRECTORY
fData.cFileName = "." & Chr$(0)
Call FileAdd
fData.cFileName = ".." & Chr$(0)
Call FileAdd
End If
End If
End Sub
Private Sub FileAdd()
Dim x As Integer, fFile As String
fFile = fData.cFileName
x = InStr(1, fFile, Chr$(0))
If x \> 0 Then
fFile = Trim$(Left$(fFile, x - 1))
Else
fFile = ""
End If
If fFile "" Then
fData.cFileName = fFile
FileList(UBound(FileList)) = fData
ReDim Preserve FileList(0 To UBound(FileList) + 1)
End If
End Sub
Private Function CalcFTime(FTime As SYSTEMTIME) As String
Dim WT(0 To 6) As String, Datum As String
Dim Zeit As String, aa As String
WT(0) = "So"
WT(1) = "Mo"
WT(2) = "Di"
WT(3) = "Mi"
WT(4) = "Do"
WT(5) = "Fr"
WT(6) = "Sa"
With FTime
Datum = WT(.wDayOfWeek) & " " & .wDay & "." & .wMonth & "." & .wYear
aa = .wMinute
If Len(aa) = 1 Then aa = "0" & aa
Zeit = .wHour & ":" & aa
CalcFTime = Datum & " um " & Zeit
End With
End Function
Private Sub GetStatus()
Dim Buffer As String, aa As String
Dim l As Long, Inf As Long
Call InternetGetLastResponseInfo(Inf, vbNullString, l)
If Inf Then
Buffer = String(l + 1, 0)
Call InternetGetLastResponseInfo(Inf, Buffer, l)
aa = Inf & " " & Buffer
Else
aa = "Ok"
End If
Label9.Caption = aa
Label9.Refresh
End Sub
Private Sub StatusText(Text As String)
Label9.Caption = Text
Label9.Refresh
End Sub
Private Sub ButtonsConnected()
Command2.Enabled = True
Command4.Enabled = True
Command5.Enabled = False
Check1.Enabled = False
End Sub
Private Sub ButtonsDisconnected()
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = True
Check1.Enabled = True
End Sub