Simple FTP UPLOAD

Iniciado por cheatmaster, 9 Julio 2007, 16:55 PM

0 Miembros y 1 Visitante están viendo este tema.

cheatmaster

Dim ftp As New ChilkatFtp2

Dim success As Integer

' Any string unlocks the component for the 1st 30-days.
success = ftp.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
    MsgBox ftp.LastErrorText
    Exit Sub
End If

ftp.Hostname = "www.example-code.com"
ftp.Username = "example-code.com"
ftp.Password = "****"

' The default data transfer mode is "Active" as opposed to "Passive".

' Connect and login to the FTP server.
success = ftp.Connect()
If (success <> 1) Then
    MsgBox ftp.LastErrorText
    Exit Sub
End If

' Change to the remote directory where the file will be uploaded.
success = ftp.ChangeRemoteDir("junk")
If (success <> 1) Then
    MsgBox ftp.LastErrorText
    Exit Sub
End If

' Upload a file.
Dim localFilename As String
localFilename = "hamlet.xml"
Dim remoteFilename As String
remoteFilename = "hamlet.xml"

success = ftp.PutFile(localFilename,remoteFilename)
If (success <> 1) Then
    MsgBox ftp.LastErrorText
    Exit Sub
End If

ftp.Disconnect

MsgBox "File Uploaded!"



El caso.. es que me da error a causa de :

success = ftp.ChangeRemo teDir("junk")
' Upload a file.
Dim localFilename As String
localFilename = "hamlet.xml"
Dim remoteFilename As String
remoteFilename = "hamlet.xml"

El caso es q HaMLET.XML, seria lo que quiero subir, suponer q es un txt pero lo del "JUNK" nose que quiere decir, ( en ingles es chatarra  creo ) pero es que nose que pongo

Hendrix

Existe la carpeta Junk???

PD: Supongo que tendras el Class llamado ChlikatFtp2, no???

Un Saludo.  ;)

"Todos los días perdemos una docena de genios en el anonimato. Y se van. Y nadie sabe de ellos, de su historia, de su peripecia, de lo que han hecho, de sus angustias, de sus alegrías. Pero al menos una docena de genios se van todos los días sin que sepamos de ellos". - Juan Antonio Cebrián

cheatmaster

Cita de: Hendrix. en  9 Julio 2007, 17:01 PM
Existe la carpeta Junk???

PD: Supongo que tendras el Class llamado ChlikatFtp2, no???

Un Saludo.  ;)



em si si, tengo la class, pero lo de la carpeta junk es dentro del ftp ?? por que cree una, pero aun asin da error ( SI TE CONECTARAS A MSN..)

Hendrix

"Todos los días perdemos una docena de genios en el anonimato. Y se van. Y nadie sabe de ellos, de su historia, de su peripecia, de lo que han hecho, de sus angustias, de sus alegrías. Pero al menos una docena de genios se van todos los días sin que sepamos de ellos". - Juan Antonio Cebrián

cheatmaster

thx por los ejemplo hendrix, pero yo manipulando codigos nose xD siempre me cargo todo, yo quiero algo sencillito como el de mi codigo y que lo suba xDD xq el de mi codigo no lo sube Oo pLz.. xD

Hendrix

Trasteando por el ApiGuide sin querer me encontre esto:

Código (vb) [Seleccionar]
Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21               ' default for FTP servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000            ' used for FTP connections
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.dll" (ByVal hInet As Long) As Integer
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
Const PassiveConnection As Boolean = True
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net
    'E-Mail: KPDTeam@allapi.net
    Dim hConnection As Long, hOpen As Long, sOrgPath  As String
    'open an internet connection
    hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    'connect to the FTP server
    hConnection = InternetConnect(hOpen, "your ftp server", INTERNET_DEFAULT_FTP_PORT, "your login", "your password", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
    'create a buffer to store the original directory
    sOrgPath = String(MAX_PATH, 0)
    'get the directory
    FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
    'create a new directory 'testing'
    FtpCreateDirectory hConnection, "testing"
    'set the current directory to 'root/testing'
    FtpSetCurrentDirectory hConnection, "testing"
    'upload the file 'test.htm'
    FtpPutFile hConnection, "C:\test.htm", "test.htm", FTP_TRANSFER_TYPE_UNKNOWN, 0
    'rename 'test.htm' to 'apiguide.htm'
    FtpRenameFile hConnection, "test.htm", "apiguide.htm"
    'enumerate the file list from the current directory ('root/testing')
    EnumFiles hConnection
    'retrieve the file from the FTP server
    FtpGetFile hConnection, "apiguide.htm", "c:\apiguide.htm", False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0
    'delete the file from the FTP server
    FtpDeleteFile hConnection, "apiguide.htm"
    'set the current directory back to the root
    FtpSetCurrentDirectory hConnection, sOrgPath
    'remove the direcrtory 'testing'
    FtpRemoveDirectory hConnection, "testing"
    'close the FTP connection
    InternetCloseHandle hConnection
    'close the internet connection
    InternetCloseHandle hOpen
End Sub
Public Sub EnumFiles(hConnection As Long)
    Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
    'set the graphics mode to persistent
    Me.AutoRedraw = True
    'create a buffer
    pData.cFileName = String(MAX_PATH, 0)
    'find the first file
    hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
    'if there's no file, then exit sub
    If hFind = 0 Then Exit Sub
    'show the filename
    Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Do
        'create a buffer
        pData.cFileName = String(MAX_PATH, 0)
        'find the next file
        lRet = InternetFindNextFile(hFind, pData)
        'if there's no next file, exit do
        If lRet = 0 Then Exit Do
        'show the filename
        Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Loop
    'close the search handle
    InternetCloseHandle hFind
End Sub
Sub ShowError()
    Dim lErr As Long, sErr As String, lenBuf As Long
    'get the required buffer size
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'create a buffer
    sErr = String(lenBuf, 0)
    'retrieve the last respons info
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'show the last response info
    MsgBox "Error " + CStr(lErr) + ": " + sErr, vbOKOnly + vbCritical
End Sub


Es un ejemplo de como conectarte al FTP y subir un archivo

Un Saludo.  ;)

"Todos los días perdemos una docena de genios en el anonimato. Y se van. Y nadie sabe de ellos, de su historia, de su peripecia, de lo que han hecho, de sus angustias, de sus alegrías. Pero al menos una docena de genios se van todos los días sin que sepamos de ellos". - Juan Antonio Cebrián

ubetor^^

Una forma mu sencilla es utilizando el componenete "Microsoft Internet Transfer Control 6"; Te lo da todo hecho...esta sería la sintaxis para subir un archivo:

Inet1.Execute "ftp://user:pass@ftp.usuarios.lycos.es", "PUT prueba.txt " & "prueba.txt"

Donde PUT va el nombre del archivo que quieres subir (pones el directorio si no está en la misma carpeta que el programa). Donde "prueba.txt" es el nombre con el que lo quieres subir al FTP.

salu2

‭‭‭‭jackl007


Este codigo es lo uso para mis cosillas, incluso para mi keyloger.

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 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 Booleanwe
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 Boolean
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_DEFAULT_FTP_PORT = 21
Const INTERNET_SERVICE_FTP = 1
Const PassiveConnection As Boolean = True
Const INTERNET_FLAG_PASSIVE = &H8000000
Const FTP_TRANSFER_TYPE_UNKNOWN = &H0

Dim hConnection, hOpen, Num As Long
Private Sub Upload()
Path = Ruta de tu archivo
hOpen = InternetOpen("IE", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
DoEvents
hConnection = InternetConnect(hOpen, "ftp.tudominio.com", INTERNET_DEFAULT_FTP_PORT, "usuario", "clave", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
DoEvents
FtpSetCurrentDirectory hConnection, "\"
DoEvents
FtpPutFile hConnection, Path, "nombredelarchivo subido.extensión", FTP_TRANSFER_TYPE_UNKNOWN, 0
DoEvents
InternetCloseHandle hConnection
InternetCloseHandle hOpen

End Sub