Re: unable to delete file on remote server - WeOnlyDo Discussion board

Re: unable to delete file on remote server (General questions)

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


Complete thread: