• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2191
  • Last Modified:

Verify copy via SSH in .net using Tamir.SharpSsh

I need some help adding a verification to the following code that is working well.

What I need to happen is a verifcation before the file is deleted.
I can't lose the file it would be difficult to replace. The files I am moving are sent daily.
Anyone have any ideas?
Thank You,
Jeremy

sftp = New Tamir.SharpSsh.Sftp(My.Settings.Item("sftp_server").ToString, My.Settings.Item("sftp_user").ToString, My.Settings.Item("sftp_pass").ToString)
            sftp.Connect()

            Dim dirlist As System.Collections.ArrayList = sftp.GetFileList(My.Settings.Item("sftp_remotedir_home").ToString)
            For i As Integer = 3 To dirlist.Count - 1

                ' Create the SFTP session and get the selected file.
                sftp = New Tamir.SharpSsh.Sftp(My.Settings.Item("sftp_server").ToString, My.Settings.Item("sftp_user").ToString, My.Settings.Item("sftp_pass").ToString)
                sftp.Connect()
                sftp.Get(My.Settings.Item("sftp_remotedir_home").ToString & "/" & dirlist.Item(i).ToString, My.Settings.Item("sftp_localdir").ToString & "home\" & dirlist.Item(i).ToString)
                sftp.Delete(My.Settings.Item("sftp_remotedir_home").ToString & "/" & dirlist.Item(i).ToString)
                sftp.Close()
                sftp = Nothing
                Dim filename As String = dirlist.Item(i).ToString
                loadfile(filename)
            Next

0
jeremy4help
Asked:
jeremy4help
  • 3
  • 2
1 Solution
 
CodeCruiserCommented:
Are you downloading the file from the server?
0
 
jeremy4helpAuthor Commented:
Yes, and saving it to a local cifs share.
The code above works. My concern is if a network hiccup happens during the transer it may error but the file will be deleted anyway.
0
 
CodeCruiserCommented:
Wrap the code in try catch. also, before deleting the file, try opening it to make sure it exists locally.
0
 
jeremy4helpAuthor Commented:
thank you I think I see it mind if i keep this open till i finish
0
 
jeremy4helpAuthor Commented:
It was a text file so I checked the last line and made sure it was complete thank you

sftp = New Tamir.SharpSsh.Sftp(My.Settings.Item("sftp_server").ToString, My.Settings.Item("sftp_user").ToString, My.Settings.Item("sftp_pass").ToString)
            sftp.Connect()

            Dim dirlist As System.Collections.ArrayList = sftp.GetFileList(My.Settings.Item("sftp_remotedir_home").ToString)
            For i As Integer = 3 To dirlist.Count - 1

                ' Create the SFTP session and get the selected file.
                sftp = New Tamir.SharpSsh.Sftp(My.Settings.Item("sftp_server").ToString, My.Settings.Item("sftp_user").ToString, My.Settings.Item("sftp_pass").ToString)
                sftp.Connect()
                sftp.Get(My.Settings.Item("sftp_remotedir_home").ToString & "/" & dirlist.Item(i).ToString, My.Settings.Item("sftp_localdir").ToString & "home\" & dirlist.Item(i).ToString)
Dim aoutput = file1(file1.Length - 1)
           Dim ans As String = aoutput.Substring(1031, 26).Trim
           If Not IsNumeric(ans) Then Throw New Exception("File is not Valid")                
sftp.Delete(My.Settings.Item("sftp_remotedir_home").ToString & "/" & dirlist.Item(i).ToString)
                sftp.Close()
                sftp = Nothing
                Dim filename As String = dirlist.Item(i).ToString
                loadfile(filename)
            Next
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now