unable to delete file on remote server - WeOnlyDo Discussion board

unable to delete file on remote server (General questions)

by Shaz Rashid, Wednesday, March 09, 2005, 14:39 (7198 days ago)

Hello,
Iam trying to delete a remote file, after file is deleted the done event is not fired, instead disconnected event is triggered, what may be the reason behind this. I want to delete multiple files on the remote server. It would be very helpful if you could help me with som e code in VB

Regards,
Shaz Rashid

Re: unable to delete file on remote server

by wodSupport, Wednesday, March 09, 2005, 15:40 (7198 days ago) @ Shaz Rashid

Shaz,

hmm. Do you do this immediately after you connect? Do you use Blocking = True? Can you paste your current code?

Basically, doing this should be easy:

Sftp.Hostname = something
sftp.Login = something
sftp.password = something
sftp.blocking = 1
sftp.Connect

sftp.DeleteFile /home/joe/somefile

and that's it.

If you don't want to use blocking, then move DeleteFile call to Connected event body.

Re: unable to delete file on remote server

by Shaz Rashid, Thursday, March 10, 2005, 06:45 (7197 days ago) @ wodSupport

Shaz,

hmm. Do you do this immediately after you connect? Do you use Blocking = True? Can you paste your current code?

Basically, doing this should be easy:

Sftp.Hostname = something
sftp.Login = something
sftp.password = something
sftp.blocking = 1
sftp.Connect

sftp.DeleteFile /home/joe/somefile

and that's it.

If you don't want to use blocking, then move DeleteFile call to Connected event body.

hi, Iam calling the delete routine immediately after connection is
established, the delete routine is called from connected event body and blocking is set to false.
I want to delete multiple files? Here is my code.


*********************************************************************
Option Explicit
Dim WithEvents SFTP As wodSFTPCom
Dim RemoteDir As String
Dim LocalDir As String
Dim FileList As Collection
Dim deletefilename As String


Private Sub Form_Load()

Set SFTP = New wodSFTPCom
SFTP.Login = login
SFTP.Password = pwd
SFTP.HostName = 213.42.121.219
SFTP.Blocking = False

RemoteDir = /data/hoftp/shaz/
LocalDir = c:

Set FileList = New Collection

SFTP.Connect
End Sub

Private Sub SFTP_AttributesData(ByVal Items As wodSFTPCOMLib.ISftpItems)
Dim i As Integer
Dim item As SftpItem

For Each item In Items
If (item.Permissions And 16384) = 0 Then
FileList.Add item.Name
End If
Next
End Sub

Private Sub SFTP_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
If ErrorCode = 0 Then
'SFTP.Blocking = False
'SFTP.ListAttributes RemoteDir
deletefiles
Else
MsgBox ErrorText
End If
End Sub

Private Sub SFTP_Disconnected()
MsgBox Done!
End Sub

Private Sub SFTP_Done(ByVal ErrorCode As Integer, ByVal ErrorText As String)
Dim fname As String


If ErrorCode <> 0 Then
Debug.Print ERROR: & ErrorText
End If

'If FileList.Count > 0 Then

'If DeleteFlag = False Then
'fname = FileList.item(1)
'deletefilename = fname
'FileList.Remove 1
'Debug.Print Downloading & fname
'SFTP.GetFile LocalDir, RemoteDir + fname
' DeleteFlag = True
'If DeleteFlag = True Then
' fname = FileList.item(1)
' deletefilename = fname
' FileList.Remove 1
' SFTP.PutFile C:UE090305.008 , RemoteDir
' SFTP.DeleteFile

' DeleteFlag = False
'End If


'Else
'SFTP.Disconnect
'End If
End Sub

'delete all files in the collection
Public Sub deletefiles()
Dim i As Integer

'ok now here lets day i have a collection of file names
'which i want delete one by one
'the first file is deleted, the done routine is called once and after that, disconnect event is called
'done event is not raising any error

For i = 1 To filelist.count
SFTP.DeleteFile RemoteDir + filelist.item(i)
Next

End Sub

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

--Shaz Rashid

Re: unable to delete file on remote server

by wodSupport, Thursday, March 10, 2005, 07:01 (7197 days ago) @ Shaz Rashid

You cannot just call DeleteFile several times inside the loop if you don't use blocking mode. Each DeleteFile call needs some time to execute, and when he is finished executing Done event is fired - from where you can call new DeleteFile. So, you must be aware it's executed in async manner.

Or, set Blocking = True in which case it works exactly as you planned. But, in that case, get rid of events - you don't need them since you can put all command sequentially.