FTP Upload with space in filename

Just starting out? Need help? Post your questions and find answers here.
stevie1401
User
User
Posts: 82
Joined: Sat Oct 18, 2014 7:14 am

FTP Upload with space in filename

Post by stevie1401 »

This code works fine in Windows, unfortunately NOT in Linux (Ubuntu, Mint)
Does anyone have an idea how to do this in Linux?

Code: Select all


EnableExplicit
Declare ftptest()

ftptest()

Procedure ftptest()
  
  Protected  connect,change,success,gesuccesst
  Protected.s  exepath,source,target,file
  exepath=GetPathPart(ProgramFilename())
   
  
  connect= OpenFTP(#PB_Any, "sftp://myserver.com", "myName", "MyPassword")
  
  If connect>0
    Debug "successfully connected"
    Debug GetFTPDirectory(connect)
    change = SetFTPDirectory(connect, "pictures")
    Debug GetFTPDirectory(connect)
    file="my file.jpg"
    source=exepath+"userbilder/"+file
    target=file
    ;target=chr(34)+target+chr(34) ;doesn't work in Linux
    ;target=chr(34)+chr(34)+target+chr(34)+chr(34) ;doesn't work in Linux
    Debug "from "+source+" to "+target
    
    If FileSize(source)>0
      Debug source+" found"
      success = SendFTPFile(connect, source, target) 
      If success>0
        Debug "success"
      Else
        Debug "NO success"
      EndIf
    EndIf
    CloseFTP(connect)
  Else
    Debug "No connection possible."
  EndIf
  
  
  
  
  
EndProcedure


stevie1401
User
User
Posts: 82
Joined: Sat Oct 18, 2014 7:14 am

Re: FTP Upload with space in filename

Post by stevie1401 »

This works (on Windows AND Linux)

Code: Select all

target=ReplaceString(target,Chr(32),"%20")
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FTP Upload with space in filename

Post by infratec »

Maybe, to be safe, use

Code: Select all

URLEncode()
stevie1401
User
User
Posts: 82
Joined: Sat Oct 18, 2014 7:14 am

Re: FTP Upload with space in filename

Post by stevie1401 »

Unfortunately I can't do anything with that.
URLEncode() is apparently not Purbasic code
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: FTP Upload with space in filename

Post by Quin »

stevie1401 wrote: Sat Sep 07, 2024 7:43 pm Unfortunately I can't do anything with that.
URLEncode() is apparently not Purbasic code
Probably typed from memory :D
The real function name is URLEncoder(), in the HTTP section of the manual.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: FTP Upload with space in filename

Post by infratec »

I was to lazy to check the typed command :oops:
But a qiuick search should foundth right command.
stevie1401
User
User
Posts: 82
Joined: Sat Oct 18, 2014 7:14 am

Re: FTP Upload with space in filename

Post by stevie1401 »

Strange that I didn't find this...
It works great!
I didn't know that command.
Thank you very much!
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: FTP Upload with space in filename

Post by Fred »

So the filename needs to be url encoded for SFTP ? I will add it natively as it's not obvious
Post Reply