Unable to remove file using session.RemoveFiles (VB.Net)

Advertisement

kevalsavani
Joined:
Posts:
10
Location:
India

Unable to remove file using session.RemoveFiles (VB.Net)

I am not able to remove/delete file from local FTP account, below is my code

Dim sessionOptions As New SessionOptions
With sessionOptions
    .Protocol = Protocol.Ftp
    .HostName = "192.168.0.3"
    .UserName = ftp_username
    .Password = ftp_password
End With
Using session As New WinSCP.Session
    session.Open(sessionOptions)
    Dim result = session.RemoveFiles("/app/log.txt")
    For Each x In result.Failures
        Debug.Print(x.ToString())
    Next
    Debug.Print(result.IsSuccess)
End Using

Here is output:
WinSCP.SessionRemoteException: Can't get attributes of file '/app/log.txt'.
Could not retrieve file information
Unknow command
False
If I do
session.RemoveFiles("/app/*.txt")
which deletes all files but I want to delete only single-single file.

Please Help.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
34,881
Location:
Prague, Czechia

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

kevalsavani
Joined:
Posts:
10
Location:
India

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Thanks Martin, I have attached the log file, can you please check and let me know the issue.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
34,881
Location:
Prague, Czechia

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Your FTP server is broken. It announces a support for MLSD/MLST commands, while it actually does not support at least the MLST:

< 2019-08-23 20:24:11.258 211-Extensions suported:
< 2019-08-23 20:24:11.258 MLSD
< 2019-08-23 20:24:11.258 211 End.
...
. 2019-08-23 20:24:11.966 Retrieving file information...
> 2019-08-23 20:24:11.966 MLST /app/log.txt
< 2019-08-23 20:24:12.139 500 Unknow command

You can try to workaround the bug by setting FtpUseMlsd:
sessionOptions.AddRawSettings("FtpUseMlsd", "1")
https://winscp.net/eng/docs/rawsettings#ftpusemlsd

Reply with quote

kevalsavani
Joined:
Posts:
10
Location:
India

Re: Unable to remove file using session.RemoveFiles (VB.Net)

I am getting following error when set this setting
sessionOptions.AddRawSettings("FtpUseMlsd", "1")
Error
.SessionRemoteException: Lost connection.
Timeout detected. (data connection)
Could not retrieve directory listing
Can't get attributes of file '16f877.pdf'.

Also I have attached the log file.
Can you please look into this and help me out.

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Can you login and see a directory contents in WinSCP GUI? Or in any FTP client at all?

Reply with quote

Guest

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Yes I can see, even I can delete files from WinSCP GUI.
Do I have any version issue or it is something else?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
34,881
Location:
Prague, Czechia

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Try this:
sessionOptions.AddRawSettings("FtpDeleteFromCwd", "0")

Please post a log file from the script and GUI in any case.

Reply with quote

kevalsavani
Joined:
Posts:
10
Location:
India

Re: Unable to remove file using session.RemoveFiles (VB.Net)

I did tried with options but no luck,
I have attached the file log, from .net and from GUI also.
Please check and let me know what can make this fix, thanks.

Reply with quote

Advertisement

kevalsavani
Joined:
Posts:
10
Location:
India

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Still getting same issue
.SessionRemoteException: Lost connection.
Timeout detected. (data connection)
Could not retrieve directory listing
Can't get attributes of file '74hc04.pdf'.
I have attached the log.

Reply with quote

martin
Site Admin
martin avatar

Re: Unable to remove file using session.RemoveFiles (VB.Net)

OK, I see. The server does not announce a support for SIZE and MDTM commands.

Anyway, at least the LIST should work. Can you connect to that server and see the directory listing using WinSCP GUI or any other FTP client, running on the same machine as your code?

Reply with quote

kevalsavani

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Yes, listing and uploading are working fine, quite slow but working fine.
can you please help me out? my client is waiting for this to get a fix so he can start production of devices.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
34,881
Location:
Prague, Czechia

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

kevalsavani
Joined:
Posts:
10
Location:
India

Re: Unable to remove file using session.RemoveFiles (VB.Net)

I have downloaded the latest version of WinSCP and tried to remove the file but still getting the same error.
I have attached the log file, can you please check and let me know the solution.

Reply with quote

martin
Site Admin
martin avatar

Re: Unable to remove file using session.RemoveFiles (VB.Net)

Can you post a log file from WinSCP GUI showing a successful directory listing? Are you running WinSCP GUI on the same machine and in the same environment as your code?

Reply with quote

reddypa
Guest

same problem

Did this ever get solved? Same problem here, for years now. I delete files from many FTP servers via a script using .RemoveFiles, but I have one client for whom I cannot delete files via a script, yet I can just fine via the UI. Please advise.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
34,881
Location:
Prague, Czechia

Re: same problem

reddypa wrote:

Did this ever get solved? Same problem here, for years now. I delete files from many FTP servers via a script using .RemoveFiles, but I have one client for whom I cannot delete files via a script, yet I can just fine via the UI. Please advise.
Please start a new thread and post log files both from the code and the GUI.

Reply with quote

Advertisement

You can post new topics in this forum