[VB] FTP probleem PUT-commando

Pagina: 1
Acties:

  • chaozz
  • Registratie: Juni 2000
  • Laatst online: 23-08 22:57
ik ben bezig met de ontwikkeling van xFTP (zie sig.), maar loop tegen 1 probleem aan: lange bestandsnamen!

via SendTo worden de parameters naar xFTP doorgestuurd, in het korte bestandsnaam formaat, bijv: C:\PROGRA~1\123456~1.ZIP
dat is logisch, omdat, als er een spatie in de bestandsnaam zit, dan ziet xFTP het als 2 parameters.

tot zover geen problemen. ik converteer vervolgens de bestanden naar lange bestandsnamen, maar het PUT commando van FTP kent dezelfde beperking: lange bestandsnamen pikt hij niet!

ik gebruik deze routine:
code:
1
Inet1.Execute strAddress, "PUT " & Parameters(Counter) & " " & strFTProot & Combo1.Text & TargetName

parameters(counter) is een array met alle meegestuurde files, die ik stuk voor stuk upload (counter ophogen)

een voorbeeld van een werkende PUT:
code:
1
PUT C:\bla.zip /bla.zip

weet iemand hoe je dit probleem kunt omzeilen???

chaozz.nl | RetroGameCouch


  • chaozz
  • Registratie: Juni 2000
  • Laatst online: 23-08 22:57
hmmm.. ik had weinig response verwacht, maar dit is wel wat zuinig.

* KICK *

enfin, lange bestandnamen lukken nu. maar een spatie in de doelnaam (op de FTP) is nog steeds niet mogelijk. ik heb geprobeert om spaties te converteren naar %20, maar dan upload hij hem niet meer.

chaozz.nl | RetroGameCouch


  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 28-08 12:00

Janoz

Moderator Devschuur®

!litemod

Dat %20 is voor URL's. Kijk anders ff in de RFC van FTP hoe het gedaan zou moeten worden, of een packetsniffer tussen een ander ftp progje... Probeer anders ff "'s om de naam heen te zetten.

hmm .. het is trouwens wel een HEEL snelle kick he!.. tjongejonge... binnen een half uur.. eigenlijk zou ik er een slot op moeten zetten...

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


Verwijderd

Je moet ook geen filetransfer via INET.ocx doen...
gewoon met winsock..

Lees het bestand in (open "c:\bla.zip" for binary as #1)
dan hak je hem in stukken van.. laten we zeggen : 4000 karakters..

Je stuurt het eerste stuk op.. en op de server doe zet je een commando neer dat "OK" terug stuurt,.. zodra dat bij de client binnenkomt,.. stuur je het volgende pakket..

uiteraard krijg je een fout als je op het laatste deel van het bestand komt omdat dat kleiner is dan 4000,
daarom gebruik je

if Grootte < 4000 then
winsock.senddata "Laatste" + data
bla bla bla




en op de server zet je..
code:
1
2
3
4
If mid$(Indata,1,7)="laatste" then
 indata = mid$(indata,8,len(indata))
 put #1, indata bla bla
endif

.. oh sjit, dit werkt natuurlijk alleen als je ZELF
CLIENT & SERVER maakt,.. anders heb je er nix aan...
denk ik nu pas aan |:(

  • henkleerssen
  • Registratie: December 2000
  • Niet online

henkleerssen

Your life is as you narrate it

Misschien is het handigere om het een ander via de API te doen van Windows (als ik me niet vergis wininet.dll).

Hier is de bijbehorende code voor het putten van files via FTP...

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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

Lost volgens mij het problem met je path gelijk op. Let vooral op het comment 'URL: http://www.allapi.net .. ;)

  • chaozz
  • Registratie: Juni 2000
  • Laatst online: 23-08 22:57
ik ben in ieder geval achter het probleem. best begrijpelijk dat ik er niet achter kwam: SPATIES MOGEN OOK NIET! WS_FTP geeft ook de melding "Foei dat mag niet!"

dusse, nu werkt het perfect! ik geef ook de melding dat de bestandsnaam ongeldige karakters bevat...

xFTP is klaar!

chaozz.nl | RetroGameCouch


  • henkleerssen
  • Registratie: December 2000
  • Niet online

henkleerssen

Your life is as you narrate it

Api calls laat je maar achterwege? Het zou kunnen dat het wat performance winst geeft...

  • chaozz
  • Registratie: Juni 2000
  • Laatst online: 23-08 22:57
Op woensdag 05 juni 2002 13:33 schreef henkleerssen het volgende:
Api calls laat je maar achterwege? Het zou kunnen dat het wat performance winst geeft...
daar zeg je wat...
scheelt ook weer een ocx natuurlijk!
zal je source copy/pasten en daar eens
mee aan de slag!!!

chaozz.nl | RetroGameCouch


Verwijderd

Op woensdag 05 juni 2002 12:14 schreef chaozz het volgende:
ik ben in ieder geval achter het probleem. best begrijpelijk dat ik er niet achter kwam: SPATIES MOGEN OOK NIET! WS_FTP geeft ook de melding "Foei dat mag niet!"
Ik heb vanmiddag nog een bestandje met spatie erin met WS_FTP geupload, dus... je hebt weer wat te doen ;).

Overigens zijn er een aantal mooie gratis componentjes die geen last van dit probleem hebben, en gewoon bestanden met spaties kunnen versturen. Kijk eens op www.devpower.com

  • chaozz
  • Registratie: Juni 2000
  • Laatst online: 23-08 22:57
Op woensdag 05 juni 2002 18:52 schreef KoenM het volgende:

[..]

Ik heb vanmiddag nog een bestandje met spatie erin met WS_FTP geupload, dus... je hebt weer wat te doen ;).

Overigens zijn er een aantal mooie gratis componentjes die geen last van dit probleem hebben, en gewoon bestanden met spaties kunnen versturen. Kijk eens op www.devpower.com
WS_FTP LE (limited edition) vindt van niet hoor..

chaozz.nl | RetroGameCouch


Verwijderd

Op donderdag 06 juni 2002 08:42 schreef chaozz het volgende:
WS_FTP LE (limited edition) vindt van niet hoor..
Het MAG en KAN wel, dus zal je er (zeker als je je progje in je sig zet) rekening mee moeten houden.

Aangezien ik de oplossing ook al aangedragen heb, zie ik het probleem ook niet...

Dat het in WS_FTP LE niet mag boeit niet, want zoals de naam al aangeeft is het een zeer beperkte versie.

  • henkleerssen
  • Registratie: December 2000
  • Niet online

henkleerssen

Your life is as you narrate it

Op woensdag 05 juni 2002 14:27 schreef chaozz het volgende:

[..]

daar zeg je wat...
scheelt ook weer een ocx natuurlijk!
zal je source copy/pasten en daar eens
mee aan de slag!!!
dat bedoel ik... succes ermee
Pagina: 1