[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Verify copy via SSH in .net using Tamir.SharpSsh

Posted on 2011-05-09
5
Medium Priority
?
2,079 Views
Last Modified: 2012-05-11
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
Comment
Question by:jeremy4help
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35727382
Are you downloading the file from the server?
0
 

Author Comment

by:jeremy4help
ID: 35732017
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 35732031
Wrap the code in try catch. also, before deleting the file, try opening it to make sure it exists locally.
0
 

Author Comment

by:jeremy4help
ID: 35732704
thank you I think I see it mind if i keep this open till i finish
0
 

Author Comment

by:jeremy4help
ID: 35750152
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question