Page 1 of 1

FTP Upload with space in filename

Posted: Sat Sep 07, 2024 8:38 am
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



Re: FTP Upload with space in filename

Posted: Sat Sep 07, 2024 3:22 pm
by stevie1401
This works (on Windows AND Linux)

Code: Select all

target=ReplaceString(target,Chr(32),"%20")

Re: FTP Upload with space in filename

Posted: Sat Sep 07, 2024 5:37 pm
by infratec
Maybe, to be safe, use

Code: Select all

URLEncode()

Re: FTP Upload with space in filename

Posted: Sat Sep 07, 2024 7:43 pm
by stevie1401
Unfortunately I can't do anything with that.
URLEncode() is apparently not Purbasic code

Re: FTP Upload with space in filename

Posted: Sat Sep 07, 2024 7:49 pm
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.

Re: FTP Upload with space in filename

Posted: Sat Sep 07, 2024 9:42 pm
by infratec
I was to lazy to check the typed command :oops:
But a qiuick search should foundth right command.

Re: FTP Upload with space in filename

Posted: Sun Sep 08, 2024 6:43 am
by stevie1401
Strange that I didn't find this...
It works great!
I didn't know that command.
Thank you very much!

Re: FTP Upload with space in filename

Posted: Sun Sep 08, 2024 10:26 am
by Fred
So the filename needs to be url encoded for SFTP ? I will add it natively as it's not obvious