Page 1 of 2

SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 3:38 pm
by Kwai chang caine
Hello at all

I don't understand.... since one day i try to remove a file, with DeleteFTPFile() without succes :|
Since the beginning and always now, i read in the doc : "you must change the current directory and not write a full path"
I have asking to AI and it say to me, write this (with full path) :

Code: Select all

Chemin$ = "/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/"
IdSftp = OpenFTP(#PB_Any, "sftp://" + IP$, Login$, Mdp$)

If IdSftp
 
 If Not DeleteFTPFile(IdSftp, Chemin$ + "kcc.txt")
  Debug "Erreur"
 EndIf
 
EndIff
i was sure that not works, but i have when even try, and i'm surprising ...that works :shock:

Then when i do that, like FRED say to do (Changing current directory)

Code: Select all

Chemin$ = "/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/"
IdSftp = OpenFTP(#PB_Any, "sftp://" + IP$, Login$, Mdp$)

If IdSftp
 
 MaxParts = CountString(Chemin$, "/") + 1
 
 For i = 1 To MaxParts
  Part$ = StringField(Chemin$, i, "/")
  SetFTPDirectory(IdSftp, Part$)
  Debug GetFTPDirectory(IdSftp)
 Next 
 
 If Not DeleteFTPFile(IdSftp, "kcc.txt")
  Debug "Error"
 EndIf
 
EndIf
I have this result
/
/var/
/var/www/
/var/www/MyCreations/
/var/www/MyCreations/Sites/
/var/www/MyCreations/Sites/Public/
/var/www/MyCreations/Sites/Public/MySite/
/var/www/MyCreations/Sites/Public/MySite/Dev/
/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/
/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/
/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/
Error
And that not works :shock:

This time...i'm really lost...what i must to do exactely ? :cry:

Have a good day

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 4:10 pm
by infratec
... it depends :wink:

The problem is that FTP/FTPS and SFTP are different.

In FTP/FTPS the delete command is DELE and in some server implementations only the filename is allowed as parameter.
So you need to change the directory before you can delete the file.

In SFTP the delete command is rm and you can use it with a full path as parameter.
SFTP has to do with ssh, the commands has more to do with a unix shell.

Maybe this should be handled by the PB procedures internally, so that you always can use a full path as parameter.

If you look in my libcurl examples, you will see:
FTPS_selete.pb:

Code: Select all

*cmdlist = curl_slist_append(#Null, "CWD " + GetPathPart(#FileToDelete$))
*cmdlist = curl_slist_append(*cmdlist, "DELE " + GetFilePart(#FileToDelete$))
So you don't need to change the directory step by step, one SetFTPDirectory() should be Ok.

SFTP_delete.pb:

Code: Select all

*cmdlist = curl_slist_append(#Null, "RM " + #FileToDelete$)
But ...
also your second code should work.
Are you sure that the file was there?

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 6:26 pm
by Kwai chang caine
Thanks a lot MASTER to your very important for me answer 8)
Yes i'm sure, i see with Filezilla, and Filllezilla have no problem for delete, create, etc...
For be sure i paste the path obtain in debug, in filezilla field and press return, and i see the file "Kcc.txt" :wink:

You have right, no need to set the current path in several time 8) , but, impossible to delete the file
In this code there is the three methods, and only the 3e works :shock:
This deletefile function is a disaster :(
If she is so complex and have several behaviour, why our good FRED not give the full exemples in the help ?

Code: Select all

Chemin$ = "/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/"
IdSftp = OpenFTP(#PB_Any, "sftp://" + IP$, Login$, Mdp$)

If IdSftp
 
 MaxParts = CountString(Chemin$, "/") + 1
 
 For i = 1 To MaxParts
  Part$ = StringField(Chemin$, i, "/")
  SetFTPDirectory(IdSftp, Part$)
  Debug GetFTPDirectory(IdSftp)
 Next 
 
 If Not DeleteFTPFile(IdSftp, "kcc.txt")
  Debug "Error 1"
 Else
  Debug "Ok 1" 
 EndIf
 
 CloseFTP(IdSftp)
 
EndIf

Debug #CRLF$ + "******************************" + #CRLF$

IdSftp = OpenFTP(#PB_Any, "sftp://" + IP$, Login$, Mdp$)

If IdSftp
 
 SetFTPDirectory(IdSftp, Chemin$)
 Debug GetFTPDirectory(IdSftp)
  
 If Not DeleteFTPFile(IdSftp, "kcc.txt")
  Debug "Error 2"
 Else
  Debug "Ok 2"
 EndIf
 
 CloseFTP(IdSftp)
 
EndIf

Debug #CRLF$ + "******************************" + #CRLF$

IdSftp = OpenFTP(#PB_Any, "sftp://" + IP$, Login$, Mdp$)

If IdSftp
 
 If Not DeleteFTPFile(IdSftp, Chemin$ + "kcc.txt")
  Debug "Error 3"
 Else
  Debug "Ok 3"
 EndIf
 
 CloseFTP(IdSftp)
 
EndIf
/
/var/
/var/www/
/var/www/MyCreations/
/var/www/MyCreations/Sites/
/var/www/MyCreations/Sites/Public/
/var/www/MyCreations/Sites/Public/MySite/
/var/www/MyCreations/Sites/Public/MySite/Dev/
/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/
/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/
/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/
Error 1

******************************

/var/www/MyCreations/Sites/Public/MySite/Dev/Sources/Php/
Error 2

******************************

Ok 3

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 8:19 pm
by infratec
I only have one explanation for this 'bug':

DeleteFTPFile() does not respect that SFTP is used if a single file is the parameter.
I think it uses than DELE instead of RM.

If you have the possibilty to see he logs of the ftp server then you can check the used commands.
Unfortunately it is crypted, so you can not see the commands in wireshark.

I think Fred should inspect this.

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 8:36 pm
by Kwai chang caine
If you have the possibilty to see he logs of the ftp server then you can check the used commands.
I not know how see it :oops:
For apache i use

Code: Select all

 tail -f /var/log/apache2/error.log

Other thing, have you an idea for my problem on your splendid code :|
viewtopic.php?p=649089#p649089

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 9:24 pm
by infratec
It depends on which ftp server is used.

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 9:34 pm
by Kwai chang caine
I have IONOS cloud S, with ubuntu 22.4 ....and don't know more :oops:

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 9:43 pm
by infratec
If you use linux you have to get familar with linux :wink:

You can use

Code: Select all

ps ax | grep ftp
It should show you a line with the running ftp server maybe it's vsftpd
If it is so:

Code: Select all

tail -f /var/log/vsftpd.log
Or look inside /etc/vsftp.conf

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 9:50 pm
by infratec
Maybe you need to increaseor enable the loging of the ftp commands

https://manpages.ubuntu.com/manpages/fo ... onf.5.html

You have to set

Code: Select all

log_ftp_protocol=YES
inside the vsftpd.conf file and restart the ftp server

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 9:54 pm
by Kwai chang caine
If you use linux you have to get familar with linux
:lol: I've been using PB for 30 years and I'm still not familiar with it. :oops:
And i not "use LINUX"...i use what IONOS want i use :mrgreen:

For the server, apparently it's not what you say to me, i have error message of LINUX
I take a look tomorow if i found that :wink:

Re: SFTP Deletefile strange behaviour

Posted: Sat Dec 20, 2025 10:03 pm
by infratec
Sorry typo by me it is:

Code: Select all

ps ax | grep ftp

Re: SFTP Deletefile strange behaviour

Posted: Sun Dec 21, 2025 12:27 pm
by Kwai chang caine
That works.. 8)
root@ubuntu:~# ps ax | grep ftp
110033 ? Ss 0:00 /usr/lib/openssh/sftp-server
110440 ? Ss 0:00 /usr/lib/openssh/sftp-server
111004 pts/0 S+ 0:00 grep --color=auto ftp
Apparently there are not a specific log for SFTP server, but i can read it in the SSH log
/var/log/auth.log

Re: SFTP Deletefile strange behaviour

Posted: Sun Dec 21, 2025 1:13 pm
by infratec
That's a bit more tricky.

The config is done in the file
/etc/ssh/sshd_config
There is an entry like:

Code: Select all

Subsystem sftp internal-sftp
You have to add or modify the log level:

Code: Select all

Subsystem sftp internal-sftp -l VERBOSE
and restart ssh

Maybe via

Code: Select all

/etc/init.d/ssh restart
That's the old way.
If it is not available you need

Code: Select all

systemctl restart ssh.service

Re: SFTP Deletefile strange behaviour

Posted: Mon Dec 22, 2025 5:03 pm
by Kwai chang caine
Apparently in UBUNTU not recognize subsystem
UBUNTU wrote:Subsystem: command not found
:|

Re: SFTP Deletefile strange behaviour

Posted: Mon Dec 22, 2025 5:22 pm
by infratec

Code: Select all

Subsystem sftp internal-sftp -l VERBOSE
Is not a command. And it should be already available as line in the file
/etc/ssh/sshd_config
You have to check if the loglevel is set, if not you need to add -l VERBOSE to the line.
and restart the program.

I hope you can edit a text file in ubuntu.