PDA

Click to See Complete Forum and Search --> : FTP Push / Long File Names


hozo
Mar 25th, 2000, 03:59 AM
Wazzz-sup fellow progy's. Here's a good one for yah.
Wrote a program that needs to push JPG's up to an ftp server, whichever one they pick in a commondialog open file window.
Basically they pick the file, then I kick in the inet.execute like this.....
INET.execute , "PUT " & filename & " /"& username & ".jpg"
(username is just a global in the program and filename is a text box) ..
It works .. EXCEPT if they browse to directory that contain spaces. IE MY PROGRAMS.. because what happens is the follow command gets sent to the ftpserver
"PUT C:\MY PROGRAMS\ME.JPG /ME.JPG"
Well this confuses the ftp server and it trys to send C:\MY and put it on the server as PROGRAMS\ME.JPG .. You get the drift. Are there any function /procedures that anyone knows of that will turn a 32bit long name into the 16bit short name (8.3 format) ? If not.. any other ideas on how to upload to an ftp server? Thanks guys.

privoli
Mar 25th, 2000, 10:50 AM
FTPFilename = ""

For x = 1 to Len(filename)

Char = Mid(filename,x,1)

if Char = " " Then
FTPFilename = FTPFilname & "%20"
else
FTPFilename = FTPFilname & Char
end if
next x

FullCmd = PUT " & FTPFilename & " /"& username & ".jpg"

Inet1.Execute FullCmd


[Edited by privoli on 03-25-2000 at 11:51 PM]

hozo
Mar 26th, 2000, 12:50 AM
DUH! Why didn't I think of that.. THANKS MAN

Mar 26th, 2000, 04:08 PM
"PUT ""C:\MY PROGRAMS\ME.JPG"" /ME.JPG" should also work

Or you could convert it to a short path:

Option Explicit
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Const MAX_PATH As Long = 260

Private Function GetShortPath(sLongPath As String) As String
Dim sBuffer As String
Dim lRet As Long
sBuffer = Space$(MAX_PATH)
lRet = GetShortPathName(sLongPath, sBuffer, MAX_PATH)
sBuffer = Left$(sBuffer, InStr(sBuffer, vbNullChar) - 1)
End Function

Private Sub Command1_Click()
MsgBox GetShortPath("C:\Program Files")
End Sub