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

Advertisement

kevalsavani
Joined:
Posts:
5
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:
31,598
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:
5
Location:
India

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

martin wrote:

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

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.


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:
31,598
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:
5
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.


martin wrote:

Your FTP server is broken. It announces a support for MLSD/MLST commands, while it actually does not support at lest 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://.net/eng/docs/rawsettings#ftpusemlsd

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
31,598
Location:
Prague, Czechia

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?

martin wrote:

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

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
31,598
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:
5
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.

martin wrote:

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

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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
31,598
Location:
Prague, Czechia

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

You still have to set the FtpUseMlsd.

Reply with quote

kevalsavani
Joined:
Posts:
5
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.

martin wrote:

You still have to set the FtpUseMlsd.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
31,598
Location:
Prague, Czechia

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

Advertisement

You can post new topics in this forum