Strona: [  << <   1   > >>  ]  z  1     
Autor Temat: wysylanie plikow na FTP
anonim




Typ: Nie zarejestrowany
wysylanie plikow na FTP

WItam!
Czy poprzez API jest jakis sposob na wyslanie pliku na FTP?? Bardzo bylbym wdzieczny za odpowiedz...

05-08-2004 11:11
  
mikmas
From ŁódĽ Stadt




Typ: neutral
Postów: 772
Zarejestrowany: Apr 2003

Nie chce mi się pisać. Podam tylko zawarto¶ć klasy wysyłaj±cej itp. na serwer:
'W class module
Const ClientName As String = "mikmas"
Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000
Const INTERNET_OPEN_TYPE_PRECONFIG = 0                    ' use registry configuration
Const INTERNET_OPEN_TYPE_DIRECT = 1                        ' direct to net
Const INTERNET_OPEN_TYPE_PROXY = 3                        ' via named proxy
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4  ' prevent using java/script/INS
Const MAX_PATH = 260
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 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 FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
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
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
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
Dim hConnection As Long
Dim sOrgPath As String
Dim hOpen As Long
'Uwaga ! Większo?ć funkcji zwraca True je?li zostały wykonane poprawnie lub False je?li wystąpił błąd


'Funkcja łącząca z serwerem FTP
'
'Argumenty:
'Server - należy podać adres serwera
'Login - Login usera
'Password - Hasło
'Port - należy podać port, domy?lnie 21
'PassiveConnection - zostawiasz true je?li chcesz aby połączenie było passywne
Public Function Connect(Server As String, Login As String, Password As String, Optional Port As Integer = 21, Optional PassiveConnection As Boolean = True) As Boolean

    hOpen = InternetOpen(ClientName, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    hConnection = InternetConnect(hOpen, Server, Port, Login, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
    If hConnection = 0 Then Connect = False: Exit Function
    Connect = True
    sOrgPath = String(MAX_PATH, 0)
    FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
End Function

'Zmienia aktualny katalog w którym się poruszamy na serwerze
'
'Argumenty:
'Dir - katalog lub ?cierzka do katalogu
Public Function ChangeDirectory(Dir As String) As Boolean
    ChangeDirectory = FtpSetCurrentDirectory(hConnection, Dir)
End Function



'Wgrywa plik na serwer
'
'Argumenty:
'LocalFile - ?cierzka do pliku który chcemy wgrać
'Output - wpisujemy pod jaką nazwą ma być wgrany plik na serwer
Public Function SendFile(LocalFile As String, Output As String) As Boolean
    SendFile = FtpPutFile(hConnection, LocalFile, Output, FTP_TRANSFER_TYPE_UNKNOWN, 0)
End Function

'Funkcja pobiera plik z serwera
'
'Argumenty:
'FileName - nazwa pliku który chcesz pobrać
'LocalFileName - wybieramy ?cierzke z nazwą pliku gdzie ma zostać pobrany plik
Public Function DownloadFile(Filename As String, LocalFileName As String) As Boolean
    DownloadFile = FtpGetFile(hConnection, Filename, LocalFileName, False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0)
End Function

'Funkcja zmienia nazwe pliku
'
'Argumenty:
'OldName - plik którego nazwe chcemy zmienić
'NewName - nowa nazwa dla pliku
Public Function RenameFile(OldName As String, NewName As String) As Boolean
    RenameFile = FtpRenameFile(hConnection, OldName, NewName)
End Function

'Funkcja pobiera nazwy wszystkich plików oraz ! KATALOGÓW ! na serwerze i zwraca je w postaci tablicy
Public Function ListFiles() As Variant
    Dim Files() As Variant
    Dim strFile As String
    Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
    pData.cFileName = String(MAX_PATH, 0)
    hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
   

    If hFind = 0 Then Exit Function
    Dim i As Integer
    ReDim Files(0)
   
Jeszczeraz:
    strFile = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    If strFile = "." Or strFile = ".." Then
      pData.cFileName = String(MAX_PATH, 0)
      lRet = InternetFindNextFile(hFind, pData)
      If lRet = 0 Then Exit Function
      GoTo Jeszczeraz
    End If
   
    Files(0) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Do
        i = i + 1
        pData.cFileName = String(MAX_PATH, 0)
        lRet = InternetFindNextFile(hFind, pData)
        If lRet = 0 Then Exit Do
        ReDim Preserve Files(i)
        Files(i) = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Loop
    InternetCloseHandle hFind
    ListFiles = Files
End Function

'Funkcja usuwa wybrany plik
'
'Argumenty:
'FileName - Należy podać nazwę usuwanego pliku
Public Function DeleteFile(Filename As String) As Boolean
    DeleteFile = FtpDeleteFile(hConnection, Filename)
End Function

'Funkcja tworzy nowy katalog
'
'Argumenty:
'Name - nazwa dla nowego katalogu
Public Function NewDir(Name As String) As Boolean
    NewDir = FtpCreateDirectory(hConnection, Name)
End Function

'Funkcja usuwająca katalog
'
'Argumenty:
'Name - nazwa katalogu do usunięcia
Public Function RemoveDir(Name As String) As Boolean
    RemoveDir = FtpRemoveDirectory(hConnection, Name)
End Function

'Rozłączanie z serwerem
Public Sub Disconnect()
    InternetCloseHandle hConnection
    InternetCloseHandle hOpen
End Sub

'Użycie:
'w module
Global FTP As New clsFTP
'w np form_load
ftp.Connect server,login,password
'i dalej się skapniesz
ftp.disconnect

[Post edytowany dnia 05-08-2004 22:13 przez mikmas]


_____________________________________________
4C;65;70;69;65;6A;20;62;79;9C;20;73;69;EA;20;
62;61;72;64;7A;69;65;6A;20;73;6B;6F;6E;63;65;
6E;74;72;6F;77;61;B3;20;6E;61;20;6F;64;70;6F;
77;69;65;64;7A;69;2C;20;61;20;6E;69;65;20;6E;
61;20;72;6F;7A;73;7A;79;66;72;6F;77;79;77;61;
6E;69;75;20;3A;50

05-08-2004 22:07
Pokaż profil mikmas  Wy¶lij email do mikmas   OdwiedĽ stronę mikmas       3632553
Wszystkich odpowiedzi: 1 :: Maxymalnie na stronę: 20
Strona: [  << <   1   > >>  ]  z  1